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