2 * Copyright (C) 2010 The Android Open Source Project
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.actionbarsherlock.app;
\r
19 import android.content.Context;
\r
20 import android.graphics.drawable.Drawable;
\r
21 import android.support.v4.app.FragmentTransaction;
\r
22 import android.util.AttributeSet;
\r
23 import android.view.Gravity;
\r
24 import android.view.View;
\r
25 import android.view.ViewDebug;
\r
26 import android.view.ViewGroup;
\r
27 import android.view.ViewGroup.MarginLayoutParams;
\r
28 import android.widget.SpinnerAdapter;
\r
31 * A window feature at the top of the activity that may display the activity title, navigation
\r
32 * modes, and other interactive items.
\r
33 * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
\r
34 * activity's window when the activity uses the system's {@link
\r
35 * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default.
\r
36 * You may otherwise add the action bar by calling {@link
\r
37 * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a
\r
38 * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property.
\r
39 * <p>By default, the action bar shows the application icon on
\r
40 * the left, followed by the activity title. If your activity has an options menu, you can make
\r
41 * select items accessible directly from the action bar as "action items". You can also
\r
42 * modify various characteristics of the action bar or remove it completely.</p>
\r
43 * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
\r
44 * android.app.Activity#getActionBar getActionBar()}.</p>
\r
45 * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions,
\r
46 * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in
\r
47 * your activity, you can enable an action mode that offers actions specific to the selected
\r
48 * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the
\r
49 * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for
\r
50 * {@link ActionBar}.
\r
51 * <div class="special reference">
\r
52 * <h3>Developer Guides</h3>
\r
53 * <p>For information about how to use the action bar, including how to add action items, navigation
\r
54 * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action
\r
55 * Bar</a> developer guide.</p>
\r
58 public abstract class ActionBar {
\r
60 * Standard navigation mode. Consists of either a logo or icon
\r
61 * and title text with an optional subtitle. Clicking any of these elements
\r
62 * will dispatch onOptionsItemSelected to the host Activity with
\r
63 * a MenuItem with item ID android.R.id.home.
\r
65 public static final int NAVIGATION_MODE_STANDARD = android.app.ActionBar.NAVIGATION_MODE_STANDARD;
\r
68 * List navigation mode. Instead of static title text this mode
\r
69 * presents a list menu for navigation within the activity.
\r
70 * e.g. this might be presented to the user as a dropdown list.
\r
72 public static final int NAVIGATION_MODE_LIST = android.app.ActionBar.NAVIGATION_MODE_LIST;
\r
75 * Tab navigation mode. Instead of static title text this mode
\r
76 * presents a series of tabs for navigation within the activity.
\r
78 public static final int NAVIGATION_MODE_TABS = android.app.ActionBar.NAVIGATION_MODE_TABS;
\r
81 * Use logo instead of icon if available. This flag will cause appropriate
\r
82 * navigation modes to use a wider logo in place of the standard icon.
\r
84 * @see #setDisplayOptions(int)
\r
85 * @see #setDisplayOptions(int, int)
\r
87 public static final int DISPLAY_USE_LOGO = android.app.ActionBar.DISPLAY_USE_LOGO;
\r
90 * Show 'home' elements in this action bar, leaving more space for other
\r
91 * navigation elements. This includes logo and icon.
\r
93 * @see #setDisplayOptions(int)
\r
94 * @see #setDisplayOptions(int, int)
\r
96 public static final int DISPLAY_SHOW_HOME = android.app.ActionBar.DISPLAY_SHOW_HOME;
\r
99 * Display the 'home' element such that it appears as an 'up' affordance.
\r
100 * e.g. show an arrow to the left indicating the action that will be taken.
\r
102 * Set this flag if selecting the 'home' button in the action bar to return
\r
103 * up by a single level in your UI rather than back to the top level or front page.
\r
105 * <p>Setting this option will implicitly enable interaction with the home/up
\r
106 * button. See {@link #setHomeButtonEnabled(boolean)}.
\r
108 * @see #setDisplayOptions(int)
\r
109 * @see #setDisplayOptions(int, int)
\r
111 public static final int DISPLAY_HOME_AS_UP = android.app.ActionBar.DISPLAY_HOME_AS_UP;
\r
114 * Show the activity title and subtitle, if present.
\r
116 * @see #setTitle(CharSequence)
\r
117 * @see #setTitle(int)
\r
118 * @see #setSubtitle(CharSequence)
\r
119 * @see #setSubtitle(int)
\r
120 * @see #setDisplayOptions(int)
\r
121 * @see #setDisplayOptions(int, int)
\r
123 public static final int DISPLAY_SHOW_TITLE = android.app.ActionBar.DISPLAY_SHOW_TITLE;
\r
126 * Show the custom view if one has been set.
\r
127 * @see #setCustomView(View)
\r
128 * @see #setDisplayOptions(int)
\r
129 * @see #setDisplayOptions(int, int)
\r
131 public static final int DISPLAY_SHOW_CUSTOM = android.app.ActionBar.DISPLAY_SHOW_CUSTOM;
\r
134 * Set the action bar into custom navigation mode, supplying a view
\r
135 * for custom navigation.
\r
137 * Custom navigation views appear between the application icon and
\r
138 * any action buttons and may use any space available there. Common
\r
139 * use cases for custom navigation views might include an auto-suggesting
\r
140 * address bar for a browser or other navigation mechanisms that do not
\r
141 * translate well to provided navigation modes.
\r
143 * @param view Custom navigation view to place in the ActionBar.
\r
145 public abstract void setCustomView(View view);
\r
148 * Set the action bar into custom navigation mode, supplying a view
\r
149 * for custom navigation.
\r
151 * <p>Custom navigation views appear between the application icon and
\r
152 * any action buttons and may use any space available there. Common
\r
153 * use cases for custom navigation views might include an auto-suggesting
\r
154 * address bar for a browser or other navigation mechanisms that do not
\r
155 * translate well to provided navigation modes.</p>
\r
157 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
\r
158 * the custom view to be displayed.</p>
\r
160 * @param view Custom navigation view to place in the ActionBar.
\r
161 * @param layoutParams How this custom view should layout in the bar.
\r
163 * @see #setDisplayOptions(int, int)
\r
165 public abstract void setCustomView(View view, LayoutParams layoutParams);
\r
168 * Set the action bar into custom navigation mode, supplying a view
\r
169 * for custom navigation.
\r
171 * <p>Custom navigation views appear between the application icon and
\r
172 * any action buttons and may use any space available there. Common
\r
173 * use cases for custom navigation views might include an auto-suggesting
\r
174 * address bar for a browser or other navigation mechanisms that do not
\r
175 * translate well to provided navigation modes.</p>
\r
177 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
\r
178 * the custom view to be displayed.</p>
\r
180 * @param resId Resource ID of a layout to inflate into the ActionBar.
\r
182 * @see #setDisplayOptions(int, int)
\r
184 public abstract void setCustomView(int resId);
\r
187 * Set the icon to display in the 'home' section of the action bar.
\r
188 * The action bar will use an icon specified by its style or the
\r
189 * activity icon by default.
\r
191 * Whether the home section shows an icon or logo is controlled
\r
192 * by the display option {@link #DISPLAY_USE_LOGO}.
\r
194 * @param resId Resource ID of a drawable to show as an icon.
\r
196 * @see #setDisplayUseLogoEnabled(boolean)
\r
197 * @see #setDisplayShowHomeEnabled(boolean)
\r
199 public abstract void setIcon(int resId);
\r
202 * Set the icon to display in the 'home' section of the action bar.
\r
203 * The action bar will use an icon specified by its style or the
\r
204 * activity icon by default.
\r
206 * Whether the home section shows an icon or logo is controlled
\r
207 * by the display option {@link #DISPLAY_USE_LOGO}.
\r
209 * @param icon Drawable to show as an icon.
\r
211 * @see #setDisplayUseLogoEnabled(boolean)
\r
212 * @see #setDisplayShowHomeEnabled(boolean)
\r
214 public abstract void setIcon(Drawable icon);
\r
217 * Set the logo to display in the 'home' section of the action bar.
\r
218 * The action bar will use a logo specified by its style or the
\r
219 * activity logo by default.
\r
221 * Whether the home section shows an icon or logo is controlled
\r
222 * by the display option {@link #DISPLAY_USE_LOGO}.
\r
224 * @param resId Resource ID of a drawable to show as a logo.
\r
226 * @see #setDisplayUseLogoEnabled(boolean)
\r
227 * @see #setDisplayShowHomeEnabled(boolean)
\r
229 public abstract void setLogo(int resId);
\r
232 * Set the logo to display in the 'home' section of the action bar.
\r
233 * The action bar will use a logo specified by its style or the
\r
234 * activity logo by default.
\r
236 * Whether the home section shows an icon or logo is controlled
\r
237 * by the display option {@link #DISPLAY_USE_LOGO}.
\r
239 * @param logo Drawable to show as a logo.
\r
241 * @see #setDisplayUseLogoEnabled(boolean)
\r
242 * @see #setDisplayShowHomeEnabled(boolean)
\r
244 public abstract void setLogo(Drawable logo);
\r
247 * Set the adapter and navigation callback for list navigation mode.
\r
249 * The supplied adapter will provide views for the expanded list as well as
\r
250 * the currently selected item. (These may be displayed differently.)
\r
252 * The supplied OnNavigationListener will alert the application when the user
\r
253 * changes the current list selection.
\r
255 * @param adapter An adapter that will provide views both to display
\r
256 * the current navigation selection and populate views
\r
257 * within the dropdown navigation menu.
\r
258 * @param callback An OnNavigationListener that will receive events when the user
\r
259 * selects a navigation item.
\r
261 public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
\r
262 OnNavigationListener callback);
\r
265 * Set the selected navigation item in list or tabbed navigation modes.
\r
267 * @param position Position of the item to select.
\r
269 public abstract void setSelectedNavigationItem(int position);
\r
272 * Get the position of the selected navigation item in list or tabbed navigation modes.
\r
274 * @return Position of the selected item.
\r
276 public abstract int getSelectedNavigationIndex();
\r
279 * Get the number of navigation items present in the current navigation mode.
\r
281 * @return Number of navigation items.
\r
283 public abstract int getNavigationItemCount();
\r
286 * Set the action bar's title. This will only be displayed if
\r
287 * {@link #DISPLAY_SHOW_TITLE} is set.
\r
289 * @param title Title to set
\r
291 * @see #setTitle(int)
\r
292 * @see #setDisplayOptions(int, int)
\r
294 public abstract void setTitle(CharSequence title);
\r
297 * Set the action bar's title. This will only be displayed if
\r
298 * {@link #DISPLAY_SHOW_TITLE} is set.
\r
300 * @param resId Resource ID of title string to set
\r
302 * @see #setTitle(CharSequence)
\r
303 * @see #setDisplayOptions(int, int)
\r
305 public abstract void setTitle(int resId);
\r
308 * Set the action bar's subtitle. This will only be displayed if
\r
309 * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
\r
310 * subtitle entirely.
\r
312 * @param subtitle Subtitle to set
\r
314 * @see #setSubtitle(int)
\r
315 * @see #setDisplayOptions(int, int)
\r
317 public abstract void setSubtitle(CharSequence subtitle);
\r
320 * Set the action bar's subtitle. This will only be displayed if
\r
321 * {@link #DISPLAY_SHOW_TITLE} is set.
\r
323 * @param resId Resource ID of subtitle string to set
\r
325 * @see #setSubtitle(CharSequence)
\r
326 * @see #setDisplayOptions(int, int)
\r
328 public abstract void setSubtitle(int resId);
\r
331 * Set display options. This changes all display option bits at once. To change
\r
332 * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
\r
334 * @param options A combination of the bits defined by the DISPLAY_ constants
\r
335 * defined in ActionBar.
\r
337 public abstract void setDisplayOptions(int options);
\r
340 * Set selected display options. Only the options specified by mask will be changed.
\r
341 * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
\r
343 * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
\r
344 * {@link #DISPLAY_SHOW_HOME} option.
\r
345 * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
\r
346 * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
\r
348 * @param options A combination of the bits defined by the DISPLAY_ constants
\r
349 * defined in ActionBar.
\r
350 * @param mask A bit mask declaring which display options should be changed.
\r
352 public abstract void setDisplayOptions(int options, int mask);
\r
355 * Set whether to display the activity logo rather than the activity icon.
\r
356 * A logo is often a wider, more detailed image.
\r
358 * <p>To set several display options at once, see the setDisplayOptions methods.
\r
360 * @param useLogo true to use the activity logo, false to use the activity icon.
\r
362 * @see #setDisplayOptions(int)
\r
363 * @see #setDisplayOptions(int, int)
\r
365 public abstract void setDisplayUseLogoEnabled(boolean useLogo);
\r
368 * Set whether to include the application home affordance in the action bar.
\r
369 * Home is presented as either an activity icon or logo.
\r
371 * <p>To set several display options at once, see the setDisplayOptions methods.
\r
373 * @param showHome true to show home, false otherwise.
\r
375 * @see #setDisplayOptions(int)
\r
376 * @see #setDisplayOptions(int, int)
\r
378 public abstract void setDisplayShowHomeEnabled(boolean showHome);
\r
381 * Set whether home should be displayed as an "up" affordance.
\r
382 * Set this to true if selecting "home" returns up by a single level in your UI
\r
383 * rather than back to the top level or front page.
\r
385 * <p>To set several display options at once, see the setDisplayOptions methods.
\r
387 * @param showHomeAsUp true to show the user that selecting home will return one
\r
388 * level up rather than to the top level of the app.
\r
390 * @see #setDisplayOptions(int)
\r
391 * @see #setDisplayOptions(int, int)
\r
393 public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
\r
396 * Set whether an activity title/subtitle should be displayed.
\r
398 * <p>To set several display options at once, see the setDisplayOptions methods.
\r
400 * @param showTitle true to display a title/subtitle if present.
\r
402 * @see #setDisplayOptions(int)
\r
403 * @see #setDisplayOptions(int, int)
\r
405 public abstract void setDisplayShowTitleEnabled(boolean showTitle);
\r
408 * Set whether a custom view should be displayed, if set.
\r
410 * <p>To set several display options at once, see the setDisplayOptions methods.
\r
412 * @param showCustom true if the currently set custom view should be displayed, false otherwise.
\r
414 * @see #setDisplayOptions(int)
\r
415 * @see #setDisplayOptions(int, int)
\r
417 public abstract void setDisplayShowCustomEnabled(boolean showCustom);
\r
420 * Set the ActionBar's background. This will be used for the primary
\r
423 * @param d Background drawable
\r
424 * @see #setStackedBackgroundDrawable(Drawable)
\r
425 * @see #setSplitBackgroundDrawable(Drawable)
\r
427 public abstract void setBackgroundDrawable(Drawable d);
\r
430 * Set the ActionBar's stacked background. This will appear
\r
431 * in the second row/stacked bar on some devices and configurations.
\r
433 * @param d Background drawable for the stacked row
\r
435 public void setStackedBackgroundDrawable(Drawable d) { }
\r
438 * Set the ActionBar's split background. This will appear in
\r
439 * the split action bar containing menu-provided action buttons
\r
440 * on some devices and configurations.
\r
441 * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
\r
443 * @param d Background drawable for the split bar
\r
445 public void setSplitBackgroundDrawable(Drawable d) { }
\r
448 * @return The current custom view.
\r
450 public abstract View getCustomView();
\r
453 * Returns the current ActionBar title in standard mode.
\r
454 * Returns null if {@link #getNavigationMode()} would not return
\r
455 * {@link #NAVIGATION_MODE_STANDARD}.
\r
457 * @return The current ActionBar title or null.
\r
459 public abstract CharSequence getTitle();
\r
462 * Returns the current ActionBar subtitle in standard mode.
\r
463 * Returns null if {@link #getNavigationMode()} would not return
\r
464 * {@link #NAVIGATION_MODE_STANDARD}.
\r
466 * @return The current ActionBar subtitle or null.
\r
468 public abstract CharSequence getSubtitle();
\r
471 * Returns the current navigation mode. The result will be one of:
\r
473 * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
\r
474 * <li>{@link #NAVIGATION_MODE_LIST}</li>
\r
475 * <li>{@link #NAVIGATION_MODE_TABS}</li>
\r
478 * @return The current navigation mode.
\r
480 public abstract int getNavigationMode();
\r
483 * Set the current navigation mode.
\r
485 * @param mode The new mode to set.
\r
486 * @see #NAVIGATION_MODE_STANDARD
\r
487 * @see #NAVIGATION_MODE_LIST
\r
488 * @see #NAVIGATION_MODE_TABS
\r
490 public abstract void setNavigationMode(int mode);
\r
493 * @return The current set of display options.
\r
495 public abstract int getDisplayOptions();
\r
498 * Create and return a new {@link Tab}.
\r
499 * This tab will not be included in the action bar until it is added.
\r
501 * <p>Very often tabs will be used to switch between {@link Fragment}
\r
502 * objects. Here is a typical implementation of such tabs:</p>
\r
504 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
\r
507 * @return A new Tab
\r
509 * @see #addTab(Tab)
\r
511 public abstract Tab newTab();
\r
514 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
\r
515 * If this is the first tab to be added it will become the selected tab.
\r
517 * @param tab Tab to add
\r
519 public abstract void addTab(Tab tab);
\r
522 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
\r
524 * @param tab Tab to add
\r
525 * @param setSelected True if the added tab should become the selected tab.
\r
527 public abstract void addTab(Tab tab, boolean setSelected);
\r
530 * Add a tab for use in tabbed navigation mode. The tab will be inserted at
\r
531 * <code>position</code>. If this is the first tab to be added it will become
\r
532 * the selected tab.
\r
534 * @param tab The tab to add
\r
535 * @param position The new position of the tab
\r
537 public abstract void addTab(Tab tab, int position);
\r
540 * Add a tab for use in tabbed navigation mode. The tab will be insterted at
\r
541 * <code>position</code>.
\r
543 * @param tab The tab to add
\r
544 * @param position The new position of the tab
\r
545 * @param setSelected True if the added tab should become the selected tab.
\r
547 public abstract void addTab(Tab tab, int position, boolean setSelected);
\r
550 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
\r
551 * and another tab will be selected if present.
\r
553 * @param tab The tab to remove
\r
555 public abstract void removeTab(Tab tab);
\r
558 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
\r
559 * and another tab will be selected if present.
\r
561 * @param position Position of the tab to remove
\r
563 public abstract void removeTabAt(int position);
\r
566 * Remove all tabs from the action bar and deselect the current tab.
\r
568 public abstract void removeAllTabs();
\r
571 * Select the specified tab. If it is not a child of this action bar it will be added.
\r
573 * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
\r
575 * @param tab Tab to select
\r
577 public abstract void selectTab(Tab tab);
\r
580 * Returns the currently selected tab if in tabbed navigation mode and there is at least
\r
583 * @return The currently selected tab or null
\r
585 public abstract Tab getSelectedTab();
\r
588 * Returns the tab at the specified index.
\r
590 * @param index Index value in the range 0-get
\r
593 public abstract Tab getTabAt(int index);
\r
596 * Returns the number of tabs currently registered with the action bar.
\r
597 * @return Tab count
\r
599 public abstract int getTabCount();
\r
602 * Retrieve the current height of the ActionBar.
\r
604 * @return The ActionBar's height
\r
606 public abstract int getHeight();
\r
609 * Show the ActionBar if it is not currently showing.
\r
610 * If the window hosting the ActionBar does not have the feature
\r
611 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
\r
612 * content to fit the new space available.
\r
614 public abstract void show();
\r
617 * Hide the ActionBar if it is currently showing.
\r
618 * If the window hosting the ActionBar does not have the feature
\r
619 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
\r
620 * content to fit the new space available.
\r
622 public abstract void hide();
\r
625 * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
\r
627 public abstract boolean isShowing();
\r
630 * Add a listener that will respond to menu visibility change events.
\r
632 * @param listener The new listener to add
\r
634 public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
\r
637 * Remove a menu visibility listener. This listener will no longer receive menu
\r
638 * visibility change events.
\r
640 * @param listener A listener to remove that was previously added
\r
642 public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
\r
645 * Enable or disable the "home" button in the corner of the action bar. (Note that this
\r
646 * is the application home/up affordance on the action bar, not the systemwide home
\r
649 * <p>This defaults to true for packages targeting < API 14. For packages targeting
\r
650 * API 14 or greater, the application should call this method to enable interaction
\r
651 * with the home/up affordance.
\r
653 * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
\r
656 * @param enabled true to enable the home button, false to disable the home button.
\r
658 public void setHomeButtonEnabled(boolean enabled) { }
\r
661 * Returns a {@link Context} with an appropriate theme for creating views that
\r
662 * will appear in the action bar. If you are inflating or instantiating custom views
\r
663 * that will appear in an action bar, you should use the Context returned by this method.
\r
664 * (This includes adapters used for list navigation mode.)
\r
665 * This will ensure that views contrast properly against the action bar.
\r
667 * @return A themed Context for creating views
\r
669 public Context getThemedContext() { return null; }
\r
672 * Listener interface for ActionBar navigation events.
\r
674 public interface OnNavigationListener {
\r
676 * This method is called whenever a navigation item in your action bar
\r
679 * @param itemPosition Position of the item clicked.
\r
680 * @param itemId ID of the item clicked.
\r
681 * @return True if the event was handled, false otherwise.
\r
683 public boolean onNavigationItemSelected(int itemPosition, long itemId);
\r
687 * Listener for receiving events when action bar menus are shown or hidden.
\r
689 public interface OnMenuVisibilityListener {
\r
691 * Called when an action bar menu is shown or hidden. Applications may want to use
\r
692 * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
\r
693 * gameplay, or other activity within the main content area.
\r
695 * @param isVisible True if an action bar menu is now visible, false if no action bar
\r
696 * menus are visible.
\r
698 public void onMenuVisibilityChanged(boolean isVisible);
\r
702 * A tab in the action bar.
\r
704 * <p>Tabs manage the hiding and showing of {@link Fragment}s.
\r
706 public static abstract class Tab {
\r
708 * An invalid position for a tab.
\r
710 * @see #getPosition()
\r
712 public static final int INVALID_POSITION = -1;
\r
715 * Return the current position of this tab in the action bar.
\r
717 * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
\r
720 public abstract int getPosition();
\r
723 * Return the icon associated with this tab.
\r
725 * @return The tab's icon
\r
727 public abstract Drawable getIcon();
\r
730 * Return the text of this tab.
\r
732 * @return The tab's text
\r
734 public abstract CharSequence getText();
\r
737 * Set the icon displayed on this tab.
\r
739 * @param icon The drawable to use as an icon
\r
740 * @return The current instance for call chaining
\r
742 public abstract Tab setIcon(Drawable icon);
\r
745 * Set the icon displayed on this tab.
\r
747 * @param resId Resource ID referring to the drawable to use as an icon
\r
748 * @return The current instance for call chaining
\r
750 public abstract Tab setIcon(int resId);
\r
753 * Set the text displayed on this tab. Text may be truncated if there is not
\r
754 * room to display the entire string.
\r
756 * @param text The text to display
\r
757 * @return The current instance for call chaining
\r
759 public abstract Tab setText(CharSequence text);
\r
762 * Set the text displayed on this tab. Text may be truncated if there is not
\r
763 * room to display the entire string.
\r
765 * @param resId A resource ID referring to the text that should be displayed
\r
766 * @return The current instance for call chaining
\r
768 public abstract Tab setText(int resId);
\r
771 * Set a custom view to be used for this tab. This overrides values set by
\r
772 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
\r
774 * @param view Custom view to be used as a tab.
\r
775 * @return The current instance for call chaining
\r
777 public abstract Tab setCustomView(View view);
\r
780 * Set a custom view to be used for this tab. This overrides values set by
\r
781 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
\r
783 * @param layoutResId A layout resource to inflate and use as a custom tab view
\r
784 * @return The current instance for call chaining
\r
786 public abstract Tab setCustomView(int layoutResId);
\r
789 * Retrieve a previously set custom view for this tab.
\r
791 * @return The custom view set by {@link #setCustomView(View)}.
\r
793 public abstract View getCustomView();
\r
796 * Give this Tab an arbitrary object to hold for later use.
\r
798 * @param obj Object to store
\r
799 * @return The current instance for call chaining
\r
801 public abstract Tab setTag(Object obj);
\r
804 * @return This Tab's tag object.
\r
806 public abstract Object getTag();
\r
809 * Set the {@link TabListener} that will handle switching to and from this tab.
\r
810 * All tabs must have a TabListener set before being added to the ActionBar.
\r
812 * @param listener Listener to handle tab selection events
\r
813 * @return The current instance for call chaining
\r
815 public abstract Tab setTabListener(TabListener listener);
\r
818 * Select this tab. Only valid if the tab has been added to the action bar.
\r
820 public abstract void select();
\r
823 * Set a description of this tab's content for use in accessibility support.
\r
824 * If no content description is provided the title will be used.
\r
826 * @param resId A resource ID referring to the description text
\r
827 * @return The current instance for call chaining
\r
828 * @see #setContentDescription(CharSequence)
\r
829 * @see #getContentDescription()
\r
831 public abstract Tab setContentDescription(int resId);
\r
834 * Set a description of this tab's content for use in accessibility support.
\r
835 * If no content description is provided the title will be used.
\r
837 * @param contentDesc Description of this tab's content
\r
838 * @return The current instance for call chaining
\r
839 * @see #setContentDescription(int)
\r
840 * @see #getContentDescription()
\r
842 public abstract Tab setContentDescription(CharSequence contentDesc);
\r
845 * Gets a brief description of this tab's content for use in accessibility support.
\r
847 * @return Description of this tab's content
\r
848 * @see #setContentDescription(CharSequence)
\r
849 * @see #setContentDescription(int)
\r
851 public abstract CharSequence getContentDescription();
\r
855 * Callback interface invoked when a tab is focused, unfocused, added, or removed.
\r
857 public interface TabListener {
\r
859 * Called when a tab enters the selected state.
\r
861 * @param tab The tab that was selected
\r
862 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
\r
863 * during a tab switch. The previous tab's unselect and this tab's select will be
\r
864 * executed in a single transaction. This FragmentTransaction does not support
\r
865 * being added to the back stack.
\r
867 public void onTabSelected(Tab tab, FragmentTransaction ft);
\r
870 * Called when a tab exits the selected state.
\r
872 * @param tab The tab that was unselected
\r
873 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
\r
874 * during a tab switch. This tab's unselect and the newly selected tab's select
\r
875 * will be executed in a single transaction. This FragmentTransaction does not
\r
876 * support being added to the back stack.
\r
878 public void onTabUnselected(Tab tab, FragmentTransaction ft);
\r
881 * Called when a tab that is already selected is chosen again by the user.
\r
882 * Some applications may use this action to return to the top level of a category.
\r
884 * @param tab The tab that was reselected.
\r
885 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
\r
886 * once this method returns. This FragmentTransaction does not support
\r
887 * being added to the back stack.
\r
889 public void onTabReselected(Tab tab, FragmentTransaction ft);
\r
893 * Per-child layout information associated with action bar custom views.
\r
895 * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
\r
897 public static class LayoutParams extends MarginLayoutParams {
\r
899 * Gravity for the view associated with these LayoutParams.
\r
901 * @see android.view.Gravity
\r
903 @ViewDebug.ExportedProperty(mapping = {
\r
904 @ViewDebug.IntToString(from = -1, to = "NONE"),
\r
905 @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"),
\r
906 @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
\r
907 @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
\r
908 @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"),
\r
909 @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"),
\r
910 @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"),
\r
911 @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"),
\r
912 @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
\r
913 @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"),
\r
914 @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
\r
915 @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
\r
917 public int gravity = -1;
\r
919 public LayoutParams(Context c, AttributeSet attrs) {
\r
923 public LayoutParams(int width, int height) {
\r
924 super(width, height);
\r
925 this.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
\r
928 public LayoutParams(int width, int height, int gravity) {
\r
929 super(width, height);
\r
930 this.gravity = gravity;
\r
933 public LayoutParams(int gravity) {
\r
934 this(WRAP_CONTENT, FILL_PARENT, gravity);
\r
937 public LayoutParams(LayoutParams source) {
\r
940 this.gravity = source.gravity;
\r
943 public LayoutParams(ViewGroup.LayoutParams source) {
\r