• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app;
18 
19 import android.annotation.DrawableRes;
20 import android.annotation.IntDef;
21 import android.annotation.LayoutRes;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.annotation.StringRes;
25 import android.content.Context;
26 import android.content.res.Configuration;
27 import android.content.res.TypedArray;
28 import android.graphics.drawable.Drawable;
29 import android.util.AttributeSet;
30 import android.view.ActionMode;
31 import android.view.Gravity;
32 import android.view.KeyEvent;
33 import android.view.View;
34 import android.view.ViewDebug;
35 import android.view.ViewGroup;
36 import android.view.ViewHierarchyEncoder;
37 import android.view.Window;
38 import android.widget.SpinnerAdapter;
39 
40 import java.lang.annotation.Retention;
41 import java.lang.annotation.RetentionPolicy;
42 
43 /**
44  * A primary toolbar within the activity that may display the activity title, application-level
45  * navigation affordances, and other interactive items.
46  *
47  * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
48  * activity's window when the activity uses the system's {@link
49  * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default.
50  * You may otherwise add the action bar by calling {@link
51  * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a
52  * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property.
53  * </p>
54  *
55  * <p>Beginning with Android L (API level 21), the action bar may be represented by any
56  * Toolbar widget within the application layout. The application may signal to the Activity
57  * which Toolbar should be treated as the Activity's action bar. Activities that use this
58  * feature should use one of the supplied <code>.NoActionBar</code> themes, set the
59  * {@link android.R.styleable#Theme_windowActionBar windowActionBar} attribute to <code>false</code>
60  * or otherwise not request the window feature.</p>
61  *
62  * <p>By adjusting the window features requested by the theme and the layouts used for
63  * an Activity's content view, an app can use the standard system action bar on older platform
64  * releases and the newer inline toolbars on newer platform releases. The <code>ActionBar</code>
65  * object obtained from the Activity can be used to control either configuration transparently.</p>
66  *
67  * <p>When using the Holo themes the action bar shows the application icon on
68  * the left, followed by the activity title. If your activity has an options menu, you can make
69  * select items accessible directly from the action bar as "action items". You can also
70  * modify various characteristics of the action bar or remove it completely.</p>
71  *
72  * <p>When using the Material themes (default in API 21 or newer) the navigation button
73  * (formerly "Home") takes over the space previously occupied by the application icon.
74  * Apps wishing to express a stronger branding should use their brand colors heavily
75  * in the action bar and other application chrome or use a {@link #setLogo(int) logo}
76  * in place of their standard title text.</p>
77  *
78  * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
79  * android.app.Activity#getActionBar getActionBar()}.</p>
80  *
81  * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions,
82  * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in
83  * your activity, you can enable an action mode that offers actions specific to the selected
84  * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the
85  * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for
86  * {@link ActionBar}.</p>
87  *
88  * <div class="special reference">
89  * <h3>Developer Guides</h3>
90  * <p>For information about how to use the action bar, including how to add action items, navigation
91  * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action
92  * Bar</a> developer guide.</p>
93  * </div>
94  */
95 public abstract class ActionBar {
96     /** @hide */
97     @Retention(RetentionPolicy.SOURCE)
98     @IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
99     public @interface NavigationMode {}
100 
101     /**
102      * Standard navigation mode. Consists of either a logo or icon
103      * and title text with an optional subtitle. Clicking any of these elements
104      * will dispatch onOptionsItemSelected to the host Activity with
105      * a MenuItem with item ID android.R.id.home.
106      *
107      * @deprecated Action bar navigation modes are deprecated and not supported by inline
108      * toolbar action bars. Consider using other
109      * <a href="http://developer.android.com/design/patterns/navigation.html">common
110      * navigation patterns</a> instead.
111      */
112     @Deprecated
113     public static final int NAVIGATION_MODE_STANDARD = 0;
114 
115     /**
116      * List navigation mode. Instead of static title text this mode
117      * presents a list menu for navigation within the activity.
118      * e.g. this might be presented to the user as a dropdown list.
119      *
120      * @deprecated Action bar navigation modes are deprecated and not supported by inline
121      * toolbar action bars. Consider using other
122      * <a href="http://developer.android.com/design/patterns/navigation.html">common
123      * navigation patterns</a> instead.
124      */
125     @Deprecated
126     public static final int NAVIGATION_MODE_LIST = 1;
127 
128     /**
129      * Tab navigation mode. Instead of static title text this mode
130      * presents a series of tabs for navigation within the activity.
131      *
132      * @deprecated Action bar navigation modes are deprecated and not supported by inline
133      * toolbar action bars. Consider using other
134      * <a href="http://developer.android.com/design/patterns/navigation.html">common
135      * navigation patterns</a> instead.
136      */
137     @Deprecated
138     public static final int NAVIGATION_MODE_TABS = 2;
139 
140     /** @hide */
141     @Retention(RetentionPolicy.SOURCE)
142     @IntDef(flag = true,
143             value = {
144                     DISPLAY_USE_LOGO,
145                     DISPLAY_SHOW_HOME,
146                     DISPLAY_HOME_AS_UP,
147                     DISPLAY_SHOW_TITLE,
148                     DISPLAY_SHOW_CUSTOM,
149                     DISPLAY_TITLE_MULTIPLE_LINES
150             })
151     public @interface DisplayOptions {}
152 
153     /**
154      * Use logo instead of icon if available. This flag will cause appropriate
155      * navigation modes to use a wider logo in place of the standard icon.
156      *
157      * @see #setDisplayOptions(int)
158      * @see #setDisplayOptions(int, int)
159      */
160     public static final int DISPLAY_USE_LOGO = 0x1;
161 
162     /**
163      * Show 'home' elements in this action bar, leaving more space for other
164      * navigation elements. This includes logo and icon.
165      *
166      * @see #setDisplayOptions(int)
167      * @see #setDisplayOptions(int, int)
168      */
169     public static final int DISPLAY_SHOW_HOME = 0x2;
170 
171     /**
172      * Display the 'home' element such that it appears as an 'up' affordance.
173      * e.g. show an arrow to the left indicating the action that will be taken.
174      *
175      * Set this flag if selecting the 'home' button in the action bar to return
176      * up by a single level in your UI rather than back to the top level or front page.
177      *
178      * <p>Setting this option will implicitly enable interaction with the home/up
179      * button. See {@link #setHomeButtonEnabled(boolean)}.
180      *
181      * @see #setDisplayOptions(int)
182      * @see #setDisplayOptions(int, int)
183      */
184     public static final int DISPLAY_HOME_AS_UP = 0x4;
185 
186     /**
187      * Show the activity title and subtitle, if present.
188      *
189      * @see #setTitle(CharSequence)
190      * @see #setTitle(int)
191      * @see #setSubtitle(CharSequence)
192      * @see #setSubtitle(int)
193      * @see #setDisplayOptions(int)
194      * @see #setDisplayOptions(int, int)
195      */
196     public static final int DISPLAY_SHOW_TITLE = 0x8;
197 
198     /**
199      * Show the custom view if one has been set.
200      * @see #setCustomView(View)
201      * @see #setDisplayOptions(int)
202      * @see #setDisplayOptions(int, int)
203      */
204     public static final int DISPLAY_SHOW_CUSTOM = 0x10;
205 
206     /**
207      * Allow the title to wrap onto multiple lines if space is available
208      * @hide pending API approval
209      */
210     public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20;
211 
212     /**
213      * Set the action bar into custom navigation mode, supplying a view
214      * for custom navigation.
215      *
216      * Custom navigation views appear between the application icon and
217      * any action buttons and may use any space available there. Common
218      * use cases for custom navigation views might include an auto-suggesting
219      * address bar for a browser or other navigation mechanisms that do not
220      * translate well to provided navigation modes.
221      *
222      * @param view Custom navigation view to place in the ActionBar.
223      */
setCustomView(View view)224     public abstract void setCustomView(View view);
225 
226     /**
227      * Set the action bar into custom navigation mode, supplying a view
228      * for custom navigation.
229      *
230      * <p>Custom navigation views appear between the application icon and
231      * any action buttons and may use any space available there. Common
232      * use cases for custom navigation views might include an auto-suggesting
233      * address bar for a browser or other navigation mechanisms that do not
234      * translate well to provided navigation modes.</p>
235      *
236      * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
237      * the custom view to be displayed.</p>
238      *
239      * @param view Custom navigation view to place in the ActionBar.
240      * @param layoutParams How this custom view should layout in the bar.
241      *
242      * @see #setDisplayOptions(int, int)
243      */
setCustomView(View view, LayoutParams layoutParams)244     public abstract void setCustomView(View view, LayoutParams layoutParams);
245 
246     /**
247      * Set the action bar into custom navigation mode, supplying a view
248      * for custom navigation.
249      *
250      * <p>Custom navigation views appear between the application icon and
251      * any action buttons and may use any space available there. Common
252      * use cases for custom navigation views might include an auto-suggesting
253      * address bar for a browser or other navigation mechanisms that do not
254      * translate well to provided navigation modes.</p>
255      *
256      * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
257      * the custom view to be displayed.</p>
258      *
259      * @param resId Resource ID of a layout to inflate into the ActionBar.
260      *
261      * @see #setDisplayOptions(int, int)
262      */
setCustomView(@ayoutRes int resId)263     public abstract void setCustomView(@LayoutRes int resId);
264 
265     /**
266      * Set the icon to display in the 'home' section of the action bar.
267      * The action bar will use an icon specified by its style or the
268      * activity icon by default.
269      *
270      * Whether the home section shows an icon or logo is controlled
271      * by the display option {@link #DISPLAY_USE_LOGO}.
272      *
273      * @param resId Resource ID of a drawable to show as an icon.
274      *
275      * @see #setDisplayUseLogoEnabled(boolean)
276      * @see #setDisplayShowHomeEnabled(boolean)
277      */
setIcon(@rawableRes int resId)278     public abstract void setIcon(@DrawableRes int resId);
279 
280     /**
281      * Set the icon to display in the 'home' section of the action bar.
282      * The action bar will use an icon specified by its style or the
283      * activity icon by default.
284      *
285      * Whether the home section shows an icon or logo is controlled
286      * by the display option {@link #DISPLAY_USE_LOGO}.
287      *
288      * @param icon Drawable to show as an icon.
289      *
290      * @see #setDisplayUseLogoEnabled(boolean)
291      * @see #setDisplayShowHomeEnabled(boolean)
292      */
setIcon(Drawable icon)293     public abstract void setIcon(Drawable icon);
294 
295     /**
296      * Set the logo to display in the 'home' section of the action bar.
297      * The action bar will use a logo specified by its style or the
298      * activity logo by default.
299      *
300      * Whether the home section shows an icon or logo is controlled
301      * by the display option {@link #DISPLAY_USE_LOGO}.
302      *
303      * @param resId Resource ID of a drawable to show as a logo.
304      *
305      * @see #setDisplayUseLogoEnabled(boolean)
306      * @see #setDisplayShowHomeEnabled(boolean)
307      */
setLogo(@rawableRes int resId)308     public abstract void setLogo(@DrawableRes int resId);
309 
310     /**
311      * Set the logo to display in the 'home' section of the action bar.
312      * The action bar will use a logo specified by its style or the
313      * activity logo by default.
314      *
315      * Whether the home section shows an icon or logo is controlled
316      * by the display option {@link #DISPLAY_USE_LOGO}.
317      *
318      * @param logo Drawable to show as a logo.
319      *
320      * @see #setDisplayUseLogoEnabled(boolean)
321      * @see #setDisplayShowHomeEnabled(boolean)
322      */
setLogo(Drawable logo)323     public abstract void setLogo(Drawable logo);
324 
325     /**
326      * Set the adapter and navigation callback for list navigation mode.
327      *
328      * The supplied adapter will provide views for the expanded list as well as
329      * the currently selected item. (These may be displayed differently.)
330      *
331      * The supplied OnNavigationListener will alert the application when the user
332      * changes the current list selection.
333      *
334      * @param adapter An adapter that will provide views both to display
335      *                the current navigation selection and populate views
336      *                within the dropdown navigation menu.
337      * @param callback An OnNavigationListener that will receive events when the user
338      *                 selects a navigation item.
339      *
340      * @deprecated Action bar navigation modes are deprecated and not supported by inline
341      * toolbar action bars. Consider using other
342      * <a href="http://developer.android.com/design/patterns/navigation.html">common
343      * navigation patterns</a> instead.
344      */
345     @Deprecated
setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback)346     public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
347             OnNavigationListener callback);
348 
349     /**
350      * Set the selected navigation item in list or tabbed navigation modes.
351      *
352      * @param position Position of the item to select.
353      *
354      * @deprecated Action bar navigation modes are deprecated and not supported by inline
355      * toolbar action bars. Consider using other
356      * <a href="http://developer.android.com/design/patterns/navigation.html">common
357      * navigation patterns</a> instead.
358      */
359     @Deprecated
setSelectedNavigationItem(int position)360     public abstract void setSelectedNavigationItem(int position);
361 
362     /**
363      * Get the position of the selected navigation item in list or tabbed navigation modes.
364      *
365      * @return Position of the selected item.
366      *
367      * @deprecated Action bar navigation modes are deprecated and not supported by inline
368      * toolbar action bars. Consider using other
369      * <a href="http://developer.android.com/design/patterns/navigation.html">common
370      * navigation patterns</a> instead.
371      */
372     @Deprecated
getSelectedNavigationIndex()373     public abstract int getSelectedNavigationIndex();
374 
375     /**
376      * Get the number of navigation items present in the current navigation mode.
377      *
378      * @return Number of navigation items.
379      *
380      * @deprecated Action bar navigation modes are deprecated and not supported by inline
381      * toolbar action bars. Consider using other
382      * <a href="http://developer.android.com/design/patterns/navigation.html">common
383      * navigation patterns</a> instead.
384      */
385     @Deprecated
getNavigationItemCount()386     public abstract int getNavigationItemCount();
387 
388     /**
389      * Set the action bar's title. This will only be displayed if
390      * {@link #DISPLAY_SHOW_TITLE} is set.
391      *
392      * @param title Title to set
393      *
394      * @see #setTitle(int)
395      * @see #setDisplayOptions(int, int)
396      */
setTitle(CharSequence title)397     public abstract void setTitle(CharSequence title);
398 
399     /**
400      * Set the action bar's title. This will only be displayed if
401      * {@link #DISPLAY_SHOW_TITLE} is set.
402      *
403      * @param resId Resource ID of title string to set
404      *
405      * @see #setTitle(CharSequence)
406      * @see #setDisplayOptions(int, int)
407      */
setTitle(@tringRes int resId)408     public abstract void setTitle(@StringRes int resId);
409 
410     /**
411      * Set the action bar's subtitle. This will only be displayed if
412      * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
413      * subtitle entirely.
414      *
415      * @param subtitle Subtitle to set
416      *
417      * @see #setSubtitle(int)
418      * @see #setDisplayOptions(int, int)
419      */
setSubtitle(CharSequence subtitle)420     public abstract void setSubtitle(CharSequence subtitle);
421 
422     /**
423      * Set the action bar's subtitle. This will only be displayed if
424      * {@link #DISPLAY_SHOW_TITLE} is set.
425      *
426      * @param resId Resource ID of subtitle string to set
427      *
428      * @see #setSubtitle(CharSequence)
429      * @see #setDisplayOptions(int, int)
430      */
setSubtitle(@tringRes int resId)431     public abstract void setSubtitle(@StringRes int resId);
432 
433     /**
434      * Set display options. This changes all display option bits at once. To change
435      * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
436      *
437      * @param options A combination of the bits defined by the DISPLAY_ constants
438      *                defined in ActionBar.
439      */
setDisplayOptions(@isplayOptions int options)440     public abstract void setDisplayOptions(@DisplayOptions int options);
441 
442     /**
443      * Set selected display options. Only the options specified by mask will be changed.
444      * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
445      *
446      * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
447      * {@link #DISPLAY_SHOW_HOME} option.
448      * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
449      * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
450      *
451      * @param options A combination of the bits defined by the DISPLAY_ constants
452      *                defined in ActionBar.
453      * @param mask A bit mask declaring which display options should be changed.
454      */
setDisplayOptions(@isplayOptions int options, @DisplayOptions int mask)455     public abstract void setDisplayOptions(@DisplayOptions int options, @DisplayOptions int mask);
456 
457     /**
458      * Set whether to display the activity logo rather than the activity icon.
459      * A logo is often a wider, more detailed image.
460      *
461      * <p>To set several display options at once, see the setDisplayOptions methods.
462      *
463      * @param useLogo true to use the activity logo, false to use the activity icon.
464      *
465      * @see #setDisplayOptions(int)
466      * @see #setDisplayOptions(int, int)
467      */
setDisplayUseLogoEnabled(boolean useLogo)468     public abstract void setDisplayUseLogoEnabled(boolean useLogo);
469 
470     /**
471      * Set whether to include the application home affordance in the action bar.
472      * Home is presented as either an activity icon or logo.
473      *
474      * <p>To set several display options at once, see the setDisplayOptions methods.
475      *
476      * @param showHome true to show home, false otherwise.
477      *
478      * @see #setDisplayOptions(int)
479      * @see #setDisplayOptions(int, int)
480      */
setDisplayShowHomeEnabled(boolean showHome)481     public abstract void setDisplayShowHomeEnabled(boolean showHome);
482 
483     /**
484      * Set whether home should be displayed as an "up" affordance.
485      * Set this to true if selecting "home" returns up by a single level in your UI
486      * rather than back to the top level or front page.
487      *
488      * <p>To set several display options at once, see the setDisplayOptions methods.
489      *
490      * @param showHomeAsUp true to show the user that selecting home will return one
491      *                     level up rather than to the top level of the app.
492      *
493      * @see #setDisplayOptions(int)
494      * @see #setDisplayOptions(int, int)
495      */
setDisplayHomeAsUpEnabled(boolean showHomeAsUp)496     public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
497 
498     /**
499      * Set whether an activity title/subtitle should be displayed.
500      *
501      * <p>To set several display options at once, see the setDisplayOptions methods.
502      *
503      * @param showTitle true to display a title/subtitle if present.
504      *
505      * @see #setDisplayOptions(int)
506      * @see #setDisplayOptions(int, int)
507      */
setDisplayShowTitleEnabled(boolean showTitle)508     public abstract void setDisplayShowTitleEnabled(boolean showTitle);
509 
510     /**
511      * Set whether a custom view should be displayed, if set.
512      *
513      * <p>To set several display options at once, see the setDisplayOptions methods.
514      *
515      * @param showCustom true if the currently set custom view should be displayed, false otherwise.
516      *
517      * @see #setDisplayOptions(int)
518      * @see #setDisplayOptions(int, int)
519      */
setDisplayShowCustomEnabled(boolean showCustom)520     public abstract void setDisplayShowCustomEnabled(boolean showCustom);
521 
522     /**
523      * Set the ActionBar's background. This will be used for the primary
524      * action bar.
525      *
526      * @param d Background drawable
527      * @see #setStackedBackgroundDrawable(Drawable)
528      * @see #setSplitBackgroundDrawable(Drawable)
529      */
setBackgroundDrawable(@ullable Drawable d)530     public abstract void setBackgroundDrawable(@Nullable Drawable d);
531 
532     /**
533      * Set the ActionBar's stacked background. This will appear
534      * in the second row/stacked bar on some devices and configurations.
535      *
536      * @param d Background drawable for the stacked row
537      */
setStackedBackgroundDrawable(Drawable d)538     public void setStackedBackgroundDrawable(Drawable d) { }
539 
540     /**
541      * Set the ActionBar's split background. This will appear in
542      * the split action bar containing menu-provided action buttons
543      * on some devices and configurations.
544      * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
545      *
546      * @param d Background drawable for the split bar
547      */
setSplitBackgroundDrawable(Drawable d)548     public void setSplitBackgroundDrawable(Drawable d) { }
549 
550     /**
551      * @return The current custom view.
552      */
getCustomView()553     public abstract View getCustomView();
554 
555     /**
556      * Returns the current ActionBar title in standard mode.
557      * Returns null if {@link #getNavigationMode()} would not return
558      * {@link #NAVIGATION_MODE_STANDARD}.
559      *
560      * @return The current ActionBar title or null.
561      */
getTitle()562     public abstract CharSequence getTitle();
563 
564     /**
565      * Returns the current ActionBar subtitle in standard mode.
566      * Returns null if {@link #getNavigationMode()} would not return
567      * {@link #NAVIGATION_MODE_STANDARD}.
568      *
569      * @return The current ActionBar subtitle or null.
570      */
getSubtitle()571     public abstract CharSequence getSubtitle();
572 
573     /**
574      * Returns the current navigation mode. The result will be one of:
575      * <ul>
576      * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
577      * <li>{@link #NAVIGATION_MODE_LIST}</li>
578      * <li>{@link #NAVIGATION_MODE_TABS}</li>
579      * </ul>
580      *
581      * @return The current navigation mode.
582      *
583      * @deprecated Action bar navigation modes are deprecated and not supported by inline
584      * toolbar action bars. Consider using other
585      * <a href="http://developer.android.com/design/patterns/navigation.html">common
586      * navigation patterns</a> instead.
587      */
588     @Deprecated
589     @NavigationMode
getNavigationMode()590     public abstract int getNavigationMode();
591 
592     /**
593      * Set the current navigation mode.
594      *
595      * @param mode The new mode to set.
596      * @see #NAVIGATION_MODE_STANDARD
597      * @see #NAVIGATION_MODE_LIST
598      * @see #NAVIGATION_MODE_TABS
599      *
600      * @deprecated Action bar navigation modes are deprecated and not supported by inline
601      * toolbar action bars. Consider using other
602      * <a href="http://developer.android.com/design/patterns/navigation.html">common
603      * navigation patterns</a> instead.
604      */
605     @Deprecated
setNavigationMode(@avigationMode int mode)606     public abstract void setNavigationMode(@NavigationMode int mode);
607 
608     /**
609      * @return The current set of display options.
610      */
getDisplayOptions()611     public abstract int getDisplayOptions();
612 
613     /**
614      * Create and return a new {@link Tab}.
615      * This tab will not be included in the action bar until it is added.
616      *
617      * <p>Very often tabs will be used to switch between {@link Fragment}
618      * objects.  Here is a typical implementation of such tabs:</p>
619      *
620      * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
621      *      complete}
622      *
623      * @return A new Tab
624      *
625      * @see #addTab(Tab)
626      *
627      * @deprecated Action bar navigation modes are deprecated and not supported by inline
628      * toolbar action bars. Consider using other
629      * <a href="http://developer.android.com/design/patterns/navigation.html">common
630      * navigation patterns</a> instead.
631      */
632     @Deprecated
newTab()633     public abstract Tab newTab();
634 
635     /**
636      * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
637      * If this is the first tab to be added it will become the selected tab.
638      *
639      * @param tab Tab to add
640      *
641      * @deprecated Action bar navigation modes are deprecated and not supported by inline
642      * toolbar action bars. Consider using other
643      * <a href="http://developer.android.com/design/patterns/navigation.html">common
644      * navigation patterns</a> instead.
645      */
646     @Deprecated
addTab(Tab tab)647     public abstract void addTab(Tab tab);
648 
649     /**
650      * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
651      *
652      * @param tab Tab to add
653      * @param setSelected True if the added tab should become the selected tab.
654      *
655      * @deprecated Action bar navigation modes are deprecated and not supported by inline
656      * toolbar action bars. Consider using other
657      * <a href="http://developer.android.com/design/patterns/navigation.html">common
658      * navigation patterns</a> instead.
659      */
660     @Deprecated
addTab(Tab tab, boolean setSelected)661     public abstract void addTab(Tab tab, boolean setSelected);
662 
663     /**
664      * Add a tab for use in tabbed navigation mode. The tab will be inserted at
665      * <code>position</code>. If this is the first tab to be added it will become
666      * the selected tab.
667      *
668      * @param tab The tab to add
669      * @param position The new position of the tab
670      *
671      * @deprecated Action bar navigation modes are deprecated and not supported by inline
672      * toolbar action bars. Consider using other
673      * <a href="http://developer.android.com/design/patterns/navigation.html">common
674      * navigation patterns</a> instead.
675      */
676     @Deprecated
addTab(Tab tab, int position)677     public abstract void addTab(Tab tab, int position);
678 
679     /**
680      * Add a tab for use in tabbed navigation mode. The tab will be insterted at
681      * <code>position</code>.
682      *
683      * @param tab The tab to add
684      * @param position The new position of the tab
685      * @param setSelected True if the added tab should become the selected tab.
686      *
687      * @deprecated Action bar navigation modes are deprecated and not supported by inline
688      * toolbar action bars. Consider using other
689      * <a href="http://developer.android.com/design/patterns/navigation.html">common
690      * navigation patterns</a> instead.
691      */
692     @Deprecated
addTab(Tab tab, int position, boolean setSelected)693     public abstract void addTab(Tab tab, int position, boolean setSelected);
694 
695     /**
696      * Remove a tab from the action bar. If the removed tab was selected it will be deselected
697      * and another tab will be selected if present.
698      *
699      * @param tab The tab to remove
700      *
701      * @deprecated Action bar navigation modes are deprecated and not supported by inline
702      * toolbar action bars. Consider using other
703      * <a href="http://developer.android.com/design/patterns/navigation.html">common
704      * navigation patterns</a> instead.
705      */
706     @Deprecated
removeTab(Tab tab)707     public abstract void removeTab(Tab tab);
708 
709     /**
710      * Remove a tab from the action bar. If the removed tab was selected it will be deselected
711      * and another tab will be selected if present.
712      *
713      * @param position Position of the tab to remove
714      *
715      * @deprecated Action bar navigation modes are deprecated and not supported by inline
716      * toolbar action bars. Consider using other
717      * <a href="http://developer.android.com/design/patterns/navigation.html">common
718      * navigation patterns</a> instead.
719      */
720     @Deprecated
removeTabAt(int position)721     public abstract void removeTabAt(int position);
722 
723     /**
724      * Remove all tabs from the action bar and deselect the current tab.
725      *
726      * @deprecated Action bar navigation modes are deprecated and not supported by inline
727      * toolbar action bars. Consider using other
728      * <a href="http://developer.android.com/design/patterns/navigation.html">common
729      * navigation patterns</a> instead.
730      */
731     @Deprecated
removeAllTabs()732     public abstract void removeAllTabs();
733 
734     /**
735      * Select the specified tab. If it is not a child of this action bar it will be added.
736      *
737      * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
738      *
739      * @param tab Tab to select
740      *
741      * @deprecated Action bar navigation modes are deprecated and not supported by inline
742      * toolbar action bars. Consider using other
743      * <a href="http://developer.android.com/design/patterns/navigation.html">common
744      * navigation patterns</a> instead.
745      */
746     @Deprecated
selectTab(Tab tab)747     public abstract void selectTab(Tab tab);
748 
749     /**
750      * Returns the currently selected tab if in tabbed navigation mode and there is at least
751      * one tab present.
752      *
753      * @return The currently selected tab or null
754      *
755      * @deprecated Action bar navigation modes are deprecated and not supported by inline
756      * toolbar action bars. Consider using other
757      * <a href="http://developer.android.com/design/patterns/navigation.html">common
758      * navigation patterns</a> instead.
759      */
760     @Deprecated
getSelectedTab()761     public abstract Tab getSelectedTab();
762 
763     /**
764      * Returns the tab at the specified index.
765      *
766      * @param index Index value in the range 0-get
767      * @return
768      *
769      * @deprecated Action bar navigation modes are deprecated and not supported by inline
770      * toolbar action bars. Consider using other
771      * <a href="http://developer.android.com/design/patterns/navigation.html">common
772      * navigation patterns</a> instead.
773      */
774     @Deprecated
getTabAt(int index)775     public abstract Tab getTabAt(int index);
776 
777     /**
778      * Returns the number of tabs currently registered with the action bar.
779      * @return Tab count
780      *
781      * @deprecated Action bar navigation modes are deprecated and not supported by inline
782      * toolbar action bars. Consider using other
783      * <a href="http://developer.android.com/design/patterns/navigation.html">common
784      * navigation patterns</a> instead.
785      */
786     @Deprecated
getTabCount()787     public abstract int getTabCount();
788 
789     /**
790      * Retrieve the current height of the ActionBar.
791      *
792      * @return The ActionBar's height
793      */
getHeight()794     public abstract int getHeight();
795 
796     /**
797      * Show the ActionBar if it is not currently showing.
798      * If the window hosting the ActionBar does not have the feature
799      * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
800      * content to fit the new space available.
801      *
802      * <p>If you are hiding the ActionBar through
803      * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN},
804      * you should not call this function directly.
805      */
show()806     public abstract void show();
807 
808     /**
809      * Hide the ActionBar if it is currently showing.
810      * If the window hosting the ActionBar does not have the feature
811      * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
812      * content to fit the new space available.
813      *
814      * <p>Instead of calling this function directly, you can also cause an
815      * ActionBar using the overlay feature to hide through
816      * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}.
817      * Hiding the ActionBar through this system UI flag allows you to more
818      * seamlessly hide it in conjunction with other screen decorations.
819      */
hide()820     public abstract void hide();
821 
822     /**
823      * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
824      */
isShowing()825     public abstract boolean isShowing();
826 
827     /**
828      * Add a listener that will respond to menu visibility change events.
829      *
830      * @param listener The new listener to add
831      */
addOnMenuVisibilityListener(OnMenuVisibilityListener listener)832     public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
833 
834     /**
835      * Remove a menu visibility listener. This listener will no longer receive menu
836      * visibility change events.
837      *
838      * @param listener A listener to remove that was previously added
839      */
removeOnMenuVisibilityListener(OnMenuVisibilityListener listener)840     public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
841 
842     /**
843      * Enable or disable the "home" button in the corner of the action bar. (Note that this
844      * is the application home/up affordance on the action bar, not the systemwide home
845      * button.)
846      *
847      * <p>This defaults to true for packages targeting &lt; API 14. For packages targeting
848      * API 14 or greater, the application should call this method to enable interaction
849      * with the home/up affordance.
850      *
851      * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
852      * the home button.
853      *
854      * @param enabled true to enable the home button, false to disable the home button.
855      */
setHomeButtonEnabled(boolean enabled)856     public void setHomeButtonEnabled(boolean enabled) { }
857 
858     /**
859      * Returns a {@link Context} with an appropriate theme for creating views that
860      * will appear in the action bar. If you are inflating or instantiating custom views
861      * that will appear in an action bar, you should use the Context returned by this method.
862      * (This includes adapters used for list navigation mode.)
863      * This will ensure that views contrast properly against the action bar.
864      *
865      * @return A themed Context for creating views
866      */
getThemedContext()867     public Context getThemedContext() { return null; }
868 
869     /**
870      * Returns true if the Title field has been truncated during layout for lack
871      * of available space.
872      *
873      * @return true if the Title field has been truncated
874      * @hide pending API approval
875      */
isTitleTruncated()876     public boolean isTitleTruncated() { return false; }
877 
878     /**
879      * Set an alternate drawable to display next to the icon/logo/title
880      * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
881      * this mode to display an alternate selection for up navigation, such as a sliding drawer.
882      *
883      * <p>If you pass <code>null</code> to this method, the default drawable from the theme
884      * will be used.</p>
885      *
886      * <p>If you implement alternate or intermediate behavior around Up, you should also
887      * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
888      * to provide a correct description of the action for accessibility support.</p>
889      *
890      * @param indicator A drawable to use for the up indicator, or null to use the theme's default
891      *
892      * @see #setDisplayOptions(int, int)
893      * @see #setDisplayHomeAsUpEnabled(boolean)
894      * @see #setHomeActionContentDescription(int)
895      */
setHomeAsUpIndicator(Drawable indicator)896     public void setHomeAsUpIndicator(Drawable indicator) { }
897 
898     /**
899      * Set an alternate drawable to display next to the icon/logo/title
900      * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
901      * this mode to display an alternate selection for up navigation, such as a sliding drawer.
902      *
903      * <p>If you pass <code>0</code> to this method, the default drawable from the theme
904      * will be used.</p>
905      *
906      * <p>If you implement alternate or intermediate behavior around Up, you should also
907      * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
908      * to provide a correct description of the action for accessibility support.</p>
909      *
910      * @param resId Resource ID of a drawable to use for the up indicator, or null
911      *              to use the theme's default
912      *
913      * @see #setDisplayOptions(int, int)
914      * @see #setDisplayHomeAsUpEnabled(boolean)
915      * @see #setHomeActionContentDescription(int)
916      */
setHomeAsUpIndicator(@rawableRes int resId)917     public void setHomeAsUpIndicator(@DrawableRes int resId) { }
918 
919     /**
920      * Set an alternate description for the Home/Up action, when enabled.
921      *
922      * <p>This description is commonly used for accessibility/screen readers when
923      * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
924      * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
925      * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
926      * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
927      * functionality such as a sliding drawer, you should also set this to accurately
928      * describe the action.</p>
929      *
930      * <p>Setting this to <code>null</code> will use the system default description.</p>
931      *
932      * @param description New description for the Home action when enabled
933      * @see #setHomeAsUpIndicator(int)
934      * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
935      */
setHomeActionContentDescription(CharSequence description)936     public void setHomeActionContentDescription(CharSequence description) { }
937 
938     /**
939      * Set an alternate description for the Home/Up action, when enabled.
940      *
941      * <p>This description is commonly used for accessibility/screen readers when
942      * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
943      * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
944      * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
945      * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
946      * functionality such as a sliding drawer, you should also set this to accurately
947      * describe the action.</p>
948      *
949      * <p>Setting this to <code>0</code> will use the system default description.</p>
950      *
951      * @param resId Resource ID of a string to use as the new description
952      *              for the Home action when enabled
953      * @see #setHomeAsUpIndicator(int)
954      * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
955      */
setHomeActionContentDescription(@tringRes int resId)956     public void setHomeActionContentDescription(@StringRes int resId) { }
957 
958     /**
959      * Enable hiding the action bar on content scroll.
960      *
961      * <p>If enabled, the action bar will scroll out of sight along with a
962      * {@link View#setNestedScrollingEnabled(boolean) nested scrolling child} view's content.
963      * The action bar must be in {@link Window#FEATURE_ACTION_BAR_OVERLAY overlay mode}
964      * to enable hiding on content scroll.</p>
965      *
966      * <p>When partially scrolled off screen the action bar is considered
967      * {@link #hide() hidden}. A call to {@link #show() show} will cause it to return to full view.
968      * </p>
969      * @param hideOnContentScroll true to enable hiding on content scroll.
970      */
setHideOnContentScrollEnabled(boolean hideOnContentScroll)971     public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
972         if (hideOnContentScroll) {
973             throw new UnsupportedOperationException("Hide on content scroll is not supported in " +
974                     "this action bar configuration.");
975         }
976     }
977 
978     /**
979      * Return whether the action bar is configured to scroll out of sight along with
980      * a {@link View#setNestedScrollingEnabled(boolean) nested scrolling child}.
981      *
982      * @return true if hide-on-content-scroll is enabled
983      * @see #setHideOnContentScrollEnabled(boolean)
984      */
isHideOnContentScrollEnabled()985     public boolean isHideOnContentScrollEnabled() {
986         return false;
987     }
988 
989     /**
990      * Return the current vertical offset of the action bar.
991      *
992      * <p>The action bar's current hide offset is the distance that the action bar is currently
993      * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
994      * current measured {@link #getHeight() height} (fully invisible).</p>
995      *
996      * @return The action bar's offset toward its fully hidden state in pixels
997      */
getHideOffset()998     public int getHideOffset() {
999         return 0;
1000     }
1001 
1002     /**
1003      * Set the current hide offset of the action bar.
1004      *
1005      * <p>The action bar's current hide offset is the distance that the action bar is currently
1006      * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
1007      * current measured {@link #getHeight() height} (fully invisible).</p>
1008      *
1009      * @param offset The action bar's offset toward its fully hidden state in pixels.
1010      */
setHideOffset(int offset)1011     public void setHideOffset(int offset) {
1012         if (offset != 0) {
1013             throw new UnsupportedOperationException("Setting an explicit action bar hide offset " +
1014                     "is not supported in this action bar configuration.");
1015         }
1016     }
1017 
1018     /**
1019      * Set the Z-axis elevation of the action bar in pixels.
1020      *
1021      * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1022      * values are closer to the user.</p>
1023      *
1024      * @param elevation Elevation value in pixels
1025      */
setElevation(float elevation)1026     public void setElevation(float elevation) {
1027         if (elevation != 0) {
1028             throw new UnsupportedOperationException("Setting a non-zero elevation is " +
1029                     "not supported in this action bar configuration.");
1030         }
1031     }
1032 
1033     /**
1034      * Get the Z-axis elevation of the action bar in pixels.
1035      *
1036      * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1037      * values are closer to the user.</p>
1038      *
1039      * @return Elevation value in pixels
1040      */
getElevation()1041     public float getElevation() {
1042         return 0;
1043     }
1044 
1045     /** @hide */
setDefaultDisplayHomeAsUpEnabled(boolean enabled)1046     public void setDefaultDisplayHomeAsUpEnabled(boolean enabled) {
1047     }
1048 
1049     /** @hide */
setShowHideAnimationEnabled(boolean enabled)1050     public void setShowHideAnimationEnabled(boolean enabled) {
1051     }
1052 
1053     /** @hide */
onConfigurationChanged(Configuration config)1054     public void onConfigurationChanged(Configuration config) {
1055     }
1056 
1057     /** @hide */
dispatchMenuVisibilityChanged(boolean visible)1058     public void dispatchMenuVisibilityChanged(boolean visible) {
1059     }
1060 
1061     /** @hide */
startActionMode(ActionMode.Callback callback)1062     public ActionMode startActionMode(ActionMode.Callback callback) {
1063         return null;
1064     }
1065 
1066     /** @hide */
openOptionsMenu()1067     public boolean openOptionsMenu() {
1068         return false;
1069     }
1070 
1071     /** @hide */
closeOptionsMenu()1072     public boolean closeOptionsMenu() {
1073         return false;
1074     }
1075 
1076     /** @hide */
invalidateOptionsMenu()1077     public boolean invalidateOptionsMenu() {
1078         return false;
1079     }
1080 
1081     /** @hide */
onMenuKeyEvent(KeyEvent event)1082     public boolean onMenuKeyEvent(KeyEvent event) {
1083         return false;
1084     }
1085 
1086     /** @hide */
onKeyShortcut(int keyCode, KeyEvent event)1087     public boolean onKeyShortcut(int keyCode, KeyEvent event) {
1088         return false;
1089     }
1090 
1091     /** @hide */
collapseActionView()1092     public boolean collapseActionView() {
1093         return false;
1094     }
1095 
1096     /** @hide */
setWindowTitle(CharSequence title)1097     public void setWindowTitle(CharSequence title) {
1098     }
1099 
1100     /** @hide */
onDestroy()1101     public void onDestroy() {
1102     }
1103 
1104     /**
1105      * Listener interface for ActionBar navigation events.
1106      *
1107      * @deprecated Action bar navigation modes are deprecated and not supported by inline
1108      * toolbar action bars. Consider using other
1109      * <a href="http://developer.android.com/design/patterns/navigation.html">common
1110      * navigation patterns</a> instead.
1111      */
1112     @Deprecated
1113     public interface OnNavigationListener {
1114         /**
1115          * This method is called whenever a navigation item in your action bar
1116          * is selected.
1117          *
1118          * @param itemPosition Position of the item clicked.
1119          * @param itemId ID of the item clicked.
1120          * @return True if the event was handled, false otherwise.
1121          */
onNavigationItemSelected(int itemPosition, long itemId)1122         public boolean onNavigationItemSelected(int itemPosition, long itemId);
1123     }
1124 
1125     /**
1126      * Listener for receiving events when action bar menus are shown or hidden.
1127      */
1128     public interface OnMenuVisibilityListener {
1129         /**
1130          * Called when an action bar menu is shown or hidden. Applications may want to use
1131          * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
1132          * gameplay, or other activity within the main content area.
1133          *
1134          * @param isVisible True if an action bar menu is now visible, false if no action bar
1135          *                  menus are visible.
1136          */
onMenuVisibilityChanged(boolean isVisible)1137         public void onMenuVisibilityChanged(boolean isVisible);
1138     }
1139 
1140     /**
1141      * A tab in the action bar.
1142      *
1143      * <p>Tabs manage the hiding and showing of {@link Fragment}s.
1144      *
1145      * @deprecated Action bar navigation modes are deprecated and not supported by inline
1146      * toolbar action bars. Consider using other
1147      * <a href="http://developer.android.com/design/patterns/navigation.html">common
1148      * navigation patterns</a> instead.
1149      */
1150     @Deprecated
1151     public static abstract class Tab {
1152         /**
1153          * An invalid position for a tab.
1154          *
1155          * @see #getPosition()
1156          */
1157         public static final int INVALID_POSITION = -1;
1158 
1159         /**
1160          * Return the current position of this tab in the action bar.
1161          *
1162          * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
1163          *         the action bar.
1164          */
getPosition()1165         public abstract int getPosition();
1166 
1167         /**
1168          * Return the icon associated with this tab.
1169          *
1170          * @return The tab's icon
1171          */
getIcon()1172         public abstract Drawable getIcon();
1173 
1174         /**
1175          * Return the text of this tab.
1176          *
1177          * @return The tab's text
1178          */
getText()1179         public abstract CharSequence getText();
1180 
1181         /**
1182          * Set the icon displayed on this tab.
1183          *
1184          * @param icon The drawable to use as an icon
1185          * @return The current instance for call chaining
1186          */
setIcon(Drawable icon)1187         public abstract Tab setIcon(Drawable icon);
1188 
1189         /**
1190          * Set the icon displayed on this tab.
1191          *
1192          * @param resId Resource ID referring to the drawable to use as an icon
1193          * @return The current instance for call chaining
1194          */
setIcon(@rawableRes int resId)1195         public abstract Tab setIcon(@DrawableRes int resId);
1196 
1197         /**
1198          * Set the text displayed on this tab. Text may be truncated if there is not
1199          * room to display the entire string.
1200          *
1201          * @param text The text to display
1202          * @return The current instance for call chaining
1203          */
setText(CharSequence text)1204         public abstract Tab setText(CharSequence text);
1205 
1206         /**
1207          * Set the text displayed on this tab. Text may be truncated if there is not
1208          * room to display the entire string.
1209          *
1210          * @param resId A resource ID referring to the text that should be displayed
1211          * @return The current instance for call chaining
1212          */
setText(@tringRes int resId)1213         public abstract Tab setText(@StringRes int resId);
1214 
1215         /**
1216          * Set a custom view to be used for this tab. This overrides values set by
1217          * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
1218          *
1219          * @param view Custom view to be used as a tab.
1220          * @return The current instance for call chaining
1221          */
setCustomView(View view)1222         public abstract Tab setCustomView(View view);
1223 
1224         /**
1225          * Set a custom view to be used for this tab. This overrides values set by
1226          * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
1227          *
1228          * @param layoutResId A layout resource to inflate and use as a custom tab view
1229          * @return The current instance for call chaining
1230          */
setCustomView(@ayoutRes int layoutResId)1231         public abstract Tab setCustomView(@LayoutRes int layoutResId);
1232 
1233         /**
1234          * Retrieve a previously set custom view for this tab.
1235          *
1236          * @return The custom view set by {@link #setCustomView(View)}.
1237          */
getCustomView()1238         public abstract View getCustomView();
1239 
1240         /**
1241          * Give this Tab an arbitrary object to hold for later use.
1242          *
1243          * @param obj Object to store
1244          * @return The current instance for call chaining
1245          */
setTag(Object obj)1246         public abstract Tab setTag(Object obj);
1247 
1248         /**
1249          * @return This Tab's tag object.
1250          */
getTag()1251         public abstract Object getTag();
1252 
1253         /**
1254          * Set the {@link TabListener} that will handle switching to and from this tab.
1255          * All tabs must have a TabListener set before being added to the ActionBar.
1256          *
1257          * @param listener Listener to handle tab selection events
1258          * @return The current instance for call chaining
1259          */
setTabListener(TabListener listener)1260         public abstract Tab setTabListener(TabListener listener);
1261 
1262         /**
1263          * Select this tab. Only valid if the tab has been added to the action bar.
1264          */
select()1265         public abstract void select();
1266 
1267         /**
1268          * Set a description of this tab's content for use in accessibility support.
1269          * If no content description is provided the title will be used.
1270          *
1271          * @param resId A resource ID referring to the description text
1272          * @return The current instance for call chaining
1273          * @see #setContentDescription(CharSequence)
1274          * @see #getContentDescription()
1275          */
setContentDescription(@tringRes int resId)1276         public abstract Tab setContentDescription(@StringRes int resId);
1277 
1278         /**
1279          * Set a description of this tab's content for use in accessibility support.
1280          * If no content description is provided the title will be used.
1281          *
1282          * @param contentDesc Description of this tab's content
1283          * @return The current instance for call chaining
1284          * @see #setContentDescription(int)
1285          * @see #getContentDescription()
1286          */
setContentDescription(CharSequence contentDesc)1287         public abstract Tab setContentDescription(CharSequence contentDesc);
1288 
1289         /**
1290          * Gets a brief description of this tab's content for use in accessibility support.
1291          *
1292          * @return Description of this tab's content
1293          * @see #setContentDescription(CharSequence)
1294          * @see #setContentDescription(int)
1295          */
getContentDescription()1296         public abstract CharSequence getContentDescription();
1297     }
1298 
1299     /**
1300      * Callback interface invoked when a tab is focused, unfocused, added, or removed.
1301      *
1302      * @deprecated Action bar navigation modes are deprecated and not supported by inline
1303      * toolbar action bars. Consider using other
1304      * <a href="http://developer.android.com/design/patterns/navigation.html">common
1305      * navigation patterns</a> instead.
1306      */
1307     @Deprecated
1308     public interface TabListener {
1309         /**
1310          * Called when a tab enters the selected state.
1311          *
1312          * @param tab The tab that was selected
1313          * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1314          *        during a tab switch. The previous tab's unselect and this tab's select will be
1315          *        executed in a single transaction. This FragmentTransaction does not support
1316          *        being added to the back stack.
1317          */
onTabSelected(Tab tab, FragmentTransaction ft)1318         public void onTabSelected(Tab tab, FragmentTransaction ft);
1319 
1320         /**
1321          * Called when a tab exits the selected state.
1322          *
1323          * @param tab The tab that was unselected
1324          * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1325          *        during a tab switch. This tab's unselect and the newly selected tab's select
1326          *        will be executed in a single transaction. This FragmentTransaction does not
1327          *        support being added to the back stack.
1328          */
onTabUnselected(Tab tab, FragmentTransaction ft)1329         public void onTabUnselected(Tab tab, FragmentTransaction ft);
1330 
1331         /**
1332          * Called when a tab that is already selected is chosen again by the user.
1333          * Some applications may use this action to return to the top level of a category.
1334          *
1335          * @param tab The tab that was reselected.
1336          * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1337          *        once this method returns. This FragmentTransaction does not support
1338          *        being added to the back stack.
1339          */
onTabReselected(Tab tab, FragmentTransaction ft)1340         public void onTabReselected(Tab tab, FragmentTransaction ft);
1341     }
1342 
1343     /**
1344      * Per-child layout information associated with action bar custom views.
1345      *
1346      * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
1347      */
1348     public static class LayoutParams extends ViewGroup.MarginLayoutParams {
1349         /**
1350          * Gravity for the view associated with these LayoutParams.
1351          *
1352          * @see android.view.Gravity
1353          */
1354         @ViewDebug.ExportedProperty(category = "layout", mapping = {
1355                 @ViewDebug.IntToString(from =  -1,                       to = "NONE"),
1356                 @ViewDebug.IntToString(from = Gravity.NO_GRAVITY,        to = "NONE"),
1357                 @ViewDebug.IntToString(from = Gravity.TOP,               to = "TOP"),
1358                 @ViewDebug.IntToString(from = Gravity.BOTTOM,            to = "BOTTOM"),
1359                 @ViewDebug.IntToString(from = Gravity.LEFT,              to = "LEFT"),
1360                 @ViewDebug.IntToString(from = Gravity.RIGHT,             to = "RIGHT"),
1361                 @ViewDebug.IntToString(from = Gravity.START,             to = "START"),
1362                 @ViewDebug.IntToString(from = Gravity.END,               to = "END"),
1363                 @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL,   to = "CENTER_VERTICAL"),
1364                 @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL,     to = "FILL_VERTICAL"),
1365                 @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
1366                 @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL,   to = "FILL_HORIZONTAL"),
1367                 @ViewDebug.IntToString(from = Gravity.CENTER,            to = "CENTER"),
1368                 @ViewDebug.IntToString(from = Gravity.FILL,              to = "FILL")
1369         })
1370         public int gravity = Gravity.NO_GRAVITY;
1371 
LayoutParams(@onNull Context c, AttributeSet attrs)1372         public LayoutParams(@NonNull Context c, AttributeSet attrs) {
1373             super(c, attrs);
1374 
1375             TypedArray a = c.obtainStyledAttributes(attrs,
1376                     com.android.internal.R.styleable.ActionBar_LayoutParams);
1377             gravity = a.getInt(
1378                     com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity,
1379                     Gravity.NO_GRAVITY);
1380             a.recycle();
1381         }
1382 
LayoutParams(int width, int height)1383         public LayoutParams(int width, int height) {
1384             super(width, height);
1385             this.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
1386         }
1387 
LayoutParams(int width, int height, int gravity)1388         public LayoutParams(int width, int height, int gravity) {
1389             super(width, height);
1390 
1391             this.gravity = gravity;
1392         }
1393 
LayoutParams(int gravity)1394         public LayoutParams(int gravity) {
1395             this(WRAP_CONTENT, MATCH_PARENT, gravity);
1396         }
1397 
LayoutParams(LayoutParams source)1398         public LayoutParams(LayoutParams source) {
1399             super(source);
1400             this.gravity = source.gravity;
1401         }
1402 
LayoutParams(ViewGroup.LayoutParams source)1403         public LayoutParams(ViewGroup.LayoutParams source) {
1404             super(source);
1405         }
1406 
1407         /*
1408          * Note for framework developers:
1409          *
1410          * You might notice that ActionBar.LayoutParams is missing a constructor overload
1411          * for MarginLayoutParams. While it may seem like a good idea to add one, at this
1412          * point it's dangerous for source compatibility. Upon building against a new
1413          * version of the SDK an app can end up statically linking to the new MarginLayoutParams
1414          * overload, causing a crash when running on older platform versions with no other changes.
1415          */
1416 
1417         /** @hide */
1418         @Override
encodeProperties(@onNull ViewHierarchyEncoder encoder)1419         protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
1420             super.encodeProperties(encoder);
1421 
1422             encoder.addProperty("gravity", gravity);
1423         }
1424     }
1425 }
1426