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