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