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