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