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