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