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