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