2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com
.actionbarsherlock
.app
;
19 import android
.content
.Context
;
20 import android
.content
.res
.TypedArray
;
21 import android
.graphics
.drawable
.Drawable
;
22 import android
.support
.v4
.app
.FragmentTransaction
;
23 import android
.util
.AttributeSet
;
24 import android
.view
.Gravity
;
25 import android
.view
.View
;
26 import android
.view
.ViewDebug
;
27 import android
.view
.ViewGroup
;
28 import android
.view
.ViewGroup
.MarginLayoutParams
;
29 import android
.widget
.SpinnerAdapter
;
32 * A window feature at the top of the activity that may display the activity title, navigation
33 * modes, and other interactive items.
34 * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
35 * activity's window when the activity uses the system's {@link
36 * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default.
37 * You may otherwise add the action bar by calling {@link
38 * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a
39 * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property.
40 * <p>By default, the action bar shows the application icon on
41 * the left, followed by the activity title. If your activity has an options menu, you can make
42 * select items accessible directly from the action bar as "action items". You can also
43 * modify various characteristics of the action bar or remove it completely.</p>
44 * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
45 * android.app.Activity#getActionBar getActionBar()}.</p>
46 * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions,
47 * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in
48 * your activity, you can enable an action mode that offers actions specific to the selected
49 * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the
50 * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for
52 * <div class="special reference">
53 * <h3>Developer Guides</h3>
54 * <p>For information about how to use the action bar, including how to add action items, navigation
55 * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action
56 * Bar</a> developer guide.</p>
59 public abstract class ActionBar
{
61 * Standard navigation mode. Consists of either a logo or icon
62 * and title text with an optional subtitle. Clicking any of these elements
63 * will dispatch onOptionsItemSelected to the host Activity with
64 * a MenuItem with item ID android.R.id.home.
66 public static final int NAVIGATION_MODE_STANDARD
= android
.app
.ActionBar
.NAVIGATION_MODE_STANDARD
;
69 * List navigation mode. Instead of static title text this mode
70 * presents a list menu for navigation within the activity.
71 * e.g. this might be presented to the user as a dropdown list.
73 public static final int NAVIGATION_MODE_LIST
= android
.app
.ActionBar
.NAVIGATION_MODE_LIST
;
76 * Tab navigation mode. Instead of static title text this mode
77 * presents a series of tabs for navigation within the activity.
79 public static final int NAVIGATION_MODE_TABS
= android
.app
.ActionBar
.NAVIGATION_MODE_TABS
;
82 * Use logo instead of icon if available. This flag will cause appropriate
83 * navigation modes to use a wider logo in place of the standard icon.
85 * @see #setDisplayOptions(int)
86 * @see #setDisplayOptions(int, int)
88 public static final int DISPLAY_USE_LOGO
= android
.app
.ActionBar
.DISPLAY_USE_LOGO
;
91 * Show 'home' elements in this action bar, leaving more space for other
92 * navigation elements. This includes logo and icon.
94 * @see #setDisplayOptions(int)
95 * @see #setDisplayOptions(int, int)
97 public static final int DISPLAY_SHOW_HOME
= android
.app
.ActionBar
.DISPLAY_SHOW_HOME
;
100 * Display the 'home' element such that it appears as an 'up' affordance.
101 * e.g. show an arrow to the left indicating the action that will be taken.
103 * Set this flag if selecting the 'home' button in the action bar to return
104 * up by a single level in your UI rather than back to the top level or front page.
106 * <p>Setting this option will implicitly enable interaction with the home/up
107 * button. See {@link #setHomeButtonEnabled(boolean)}.
109 * @see #setDisplayOptions(int)
110 * @see #setDisplayOptions(int, int)
112 public static final int DISPLAY_HOME_AS_UP
= android
.app
.ActionBar
.DISPLAY_HOME_AS_UP
;
115 * Show the activity title and subtitle, if present.
117 * @see #setTitle(CharSequence)
118 * @see #setTitle(int)
119 * @see #setSubtitle(CharSequence)
120 * @see #setSubtitle(int)
121 * @see #setDisplayOptions(int)
122 * @see #setDisplayOptions(int, int)
124 public static final int DISPLAY_SHOW_TITLE
= android
.app
.ActionBar
.DISPLAY_SHOW_TITLE
;
127 * Show the custom view if one has been set.
128 * @see #setCustomView(View)
129 * @see #setDisplayOptions(int)
130 * @see #setDisplayOptions(int, int)
132 public static final int DISPLAY_SHOW_CUSTOM
= android
.app
.ActionBar
.DISPLAY_SHOW_CUSTOM
;
135 * Set the action bar into custom navigation mode, supplying a view
136 * for custom navigation.
138 * Custom navigation views appear between the application icon and
139 * any action buttons and may use any space available there. Common
140 * use cases for custom navigation views might include an auto-suggesting
141 * address bar for a browser or other navigation mechanisms that do not
142 * translate well to provided navigation modes.
144 * @param view Custom navigation view to place in the ActionBar.
146 public abstract void setCustomView(View view
);
149 * Set the action bar into custom navigation mode, supplying a view
150 * for custom navigation.
152 * <p>Custom navigation views appear between the application icon and
153 * any action buttons and may use any space available there. Common
154 * use cases for custom navigation views might include an auto-suggesting
155 * address bar for a browser or other navigation mechanisms that do not
156 * translate well to provided navigation modes.</p>
158 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
159 * the custom view to be displayed.</p>
161 * @param view Custom navigation view to place in the ActionBar.
162 * @param layoutParams How this custom view should layout in the bar.
164 * @see #setDisplayOptions(int, int)
166 public abstract void setCustomView(View view
, LayoutParams layoutParams
);
169 * Set the action bar into custom navigation mode, supplying a view
170 * for custom navigation.
172 * <p>Custom navigation views appear between the application icon and
173 * any action buttons and may use any space available there. Common
174 * use cases for custom navigation views might include an auto-suggesting
175 * address bar for a browser or other navigation mechanisms that do not
176 * translate well to provided navigation modes.</p>
178 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
179 * the custom view to be displayed.</p>
181 * @param resId Resource ID of a layout to inflate into the ActionBar.
183 * @see #setDisplayOptions(int, int)
185 public abstract void setCustomView(int resId
);
188 * Set the icon to display in the 'home' section of the action bar.
189 * The action bar will use an icon specified by its style or the
190 * activity icon by default.
192 * Whether the home section shows an icon or logo is controlled
193 * by the display option {@link #DISPLAY_USE_LOGO}.
195 * @param resId Resource ID of a drawable to show as an icon.
197 * @see #setDisplayUseLogoEnabled(boolean)
198 * @see #setDisplayShowHomeEnabled(boolean)
200 public abstract void setIcon(int resId
);
203 * Set the icon to display in the 'home' section of the action bar.
204 * The action bar will use an icon specified by its style or the
205 * activity icon by default.
207 * Whether the home section shows an icon or logo is controlled
208 * by the display option {@link #DISPLAY_USE_LOGO}.
210 * @param icon Drawable to show as an icon.
212 * @see #setDisplayUseLogoEnabled(boolean)
213 * @see #setDisplayShowHomeEnabled(boolean)
215 public abstract void setIcon(Drawable icon
);
218 * Set the logo to display in the 'home' section of the action bar.
219 * The action bar will use a logo specified by its style or the
220 * activity logo by default.
222 * Whether the home section shows an icon or logo is controlled
223 * by the display option {@link #DISPLAY_USE_LOGO}.
225 * @param resId Resource ID of a drawable to show as a logo.
227 * @see #setDisplayUseLogoEnabled(boolean)
228 * @see #setDisplayShowHomeEnabled(boolean)
230 public abstract void setLogo(int resId
);
233 * Set the logo to display in the 'home' section of the action bar.
234 * The action bar will use a logo specified by its style or the
235 * activity logo by default.
237 * Whether the home section shows an icon or logo is controlled
238 * by the display option {@link #DISPLAY_USE_LOGO}.
240 * @param logo Drawable to show as a logo.
242 * @see #setDisplayUseLogoEnabled(boolean)
243 * @see #setDisplayShowHomeEnabled(boolean)
245 public abstract void setLogo(Drawable logo
);
248 * Set the adapter and navigation callback for list navigation mode.
250 * The supplied adapter will provide views for the expanded list as well as
251 * the currently selected item. (These may be displayed differently.)
253 * The supplied OnNavigationListener will alert the application when the user
254 * changes the current list selection.
256 * @param adapter An adapter that will provide views both to display
257 * the current navigation selection and populate views
258 * within the dropdown navigation menu.
259 * @param callback An OnNavigationListener that will receive events when the user
260 * selects a navigation item.
262 public abstract void setListNavigationCallbacks(SpinnerAdapter adapter
,
263 OnNavigationListener callback
);
266 * Set the selected navigation item in list or tabbed navigation modes.
268 * @param position Position of the item to select.
270 public abstract void setSelectedNavigationItem(int position
);
273 * Get the position of the selected navigation item in list or tabbed navigation modes.
275 * @return Position of the selected item.
277 public abstract int getSelectedNavigationIndex();
280 * Get the number of navigation items present in the current navigation mode.
282 * @return Number of navigation items.
284 public abstract int getNavigationItemCount();
287 * Set the action bar's title. This will only be displayed if
288 * {@link #DISPLAY_SHOW_TITLE} is set.
290 * @param title Title to set
292 * @see #setTitle(int)
293 * @see #setDisplayOptions(int, int)
295 public abstract void setTitle(CharSequence title
);
298 * Set the action bar's title. This will only be displayed if
299 * {@link #DISPLAY_SHOW_TITLE} is set.
301 * @param resId Resource ID of title string to set
303 * @see #setTitle(CharSequence)
304 * @see #setDisplayOptions(int, int)
306 public abstract void setTitle(int resId
);
309 * Set the action bar's subtitle. This will only be displayed if
310 * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
313 * @param subtitle Subtitle to set
315 * @see #setSubtitle(int)
316 * @see #setDisplayOptions(int, int)
318 public abstract void setSubtitle(CharSequence subtitle
);
321 * Set the action bar's subtitle. This will only be displayed if
322 * {@link #DISPLAY_SHOW_TITLE} is set.
324 * @param resId Resource ID of subtitle string to set
326 * @see #setSubtitle(CharSequence)
327 * @see #setDisplayOptions(int, int)
329 public abstract void setSubtitle(int resId
);
332 * Set display options. This changes all display option bits at once. To change
333 * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
335 * @param options A combination of the bits defined by the DISPLAY_ constants
336 * defined in ActionBar.
338 public abstract void setDisplayOptions(int options
);
341 * Set selected display options. Only the options specified by mask will be changed.
342 * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
344 * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
345 * {@link #DISPLAY_SHOW_HOME} option.
346 * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
347 * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
349 * @param options A combination of the bits defined by the DISPLAY_ constants
350 * defined in ActionBar.
351 * @param mask A bit mask declaring which display options should be changed.
353 public abstract void setDisplayOptions(int options
, int mask
);
356 * Set whether to display the activity logo rather than the activity icon.
357 * A logo is often a wider, more detailed image.
359 * <p>To set several display options at once, see the setDisplayOptions methods.
361 * @param useLogo true to use the activity logo, false to use the activity icon.
363 * @see #setDisplayOptions(int)
364 * @see #setDisplayOptions(int, int)
366 public abstract void setDisplayUseLogoEnabled(boolean useLogo
);
369 * Set whether to include the application home affordance in the action bar.
370 * Home is presented as either an activity icon or logo.
372 * <p>To set several display options at once, see the setDisplayOptions methods.
374 * @param showHome true to show home, false otherwise.
376 * @see #setDisplayOptions(int)
377 * @see #setDisplayOptions(int, int)
379 public abstract void setDisplayShowHomeEnabled(boolean showHome
);
382 * Set whether home should be displayed as an "up" affordance.
383 * Set this to true if selecting "home" returns up by a single level in your UI
384 * rather than back to the top level or front page.
386 * <p>To set several display options at once, see the setDisplayOptions methods.
388 * @param showHomeAsUp true to show the user that selecting home will return one
389 * level up rather than to the top level of the app.
391 * @see #setDisplayOptions(int)
392 * @see #setDisplayOptions(int, int)
394 public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp
);
397 * Set whether an activity title/subtitle should be displayed.
399 * <p>To set several display options at once, see the setDisplayOptions methods.
401 * @param showTitle true to display a title/subtitle if present.
403 * @see #setDisplayOptions(int)
404 * @see #setDisplayOptions(int, int)
406 public abstract void setDisplayShowTitleEnabled(boolean showTitle
);
409 * Set whether a custom view should be displayed, if set.
411 * <p>To set several display options at once, see the setDisplayOptions methods.
413 * @param showCustom true if the currently set custom view should be displayed, false otherwise.
415 * @see #setDisplayOptions(int)
416 * @see #setDisplayOptions(int, int)
418 public abstract void setDisplayShowCustomEnabled(boolean showCustom
);
421 * Set the ActionBar's background. This will be used for the primary
424 * @param d Background drawable
425 * @see #setStackedBackgroundDrawable(Drawable)
426 * @see #setSplitBackgroundDrawable(Drawable)
428 public abstract void setBackgroundDrawable(Drawable d
);
431 * Set the ActionBar's stacked background. This will appear
432 * in the second row/stacked bar on some devices and configurations.
434 * @param d Background drawable for the stacked row
436 public void setStackedBackgroundDrawable(Drawable d
) { }
439 * Set the ActionBar's split background. This will appear in
440 * the split action bar containing menu-provided action buttons
441 * on some devices and configurations.
442 * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
444 * @param d Background drawable for the split bar
446 public void setSplitBackgroundDrawable(Drawable d
) { }
449 * @return The current custom view.
451 public abstract View
getCustomView();
454 * Returns the current ActionBar title in standard mode.
455 * Returns null if {@link #getNavigationMode()} would not return
456 * {@link #NAVIGATION_MODE_STANDARD}.
458 * @return The current ActionBar title or null.
460 public abstract CharSequence
getTitle();
463 * Returns the current ActionBar subtitle in standard mode.
464 * Returns null if {@link #getNavigationMode()} would not return
465 * {@link #NAVIGATION_MODE_STANDARD}.
467 * @return The current ActionBar subtitle or null.
469 public abstract CharSequence
getSubtitle();
472 * Returns the current navigation mode. The result will be one of:
474 * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
475 * <li>{@link #NAVIGATION_MODE_LIST}</li>
476 * <li>{@link #NAVIGATION_MODE_TABS}</li>
479 * @return The current navigation mode.
481 public abstract int getNavigationMode();
484 * Set the current navigation mode.
486 * @param mode The new mode to set.
487 * @see #NAVIGATION_MODE_STANDARD
488 * @see #NAVIGATION_MODE_LIST
489 * @see #NAVIGATION_MODE_TABS
491 public abstract void setNavigationMode(int mode
);
494 * @return The current set of display options.
496 public abstract int getDisplayOptions();
499 * Create and return a new {@link Tab}.
500 * This tab will not be included in the action bar until it is added.
502 * <p>Very often tabs will be used to switch between {@link Fragment}
503 * objects. Here is a typical implementation of such tabs:</p>
505 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
512 public abstract Tab
newTab();
515 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
516 * If this is the first tab to be added it will become the selected tab.
518 * @param tab Tab to add
520 public abstract void addTab(Tab tab
);
523 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
525 * @param tab Tab to add
526 * @param setSelected True if the added tab should become the selected tab.
528 public abstract void addTab(Tab tab
, boolean setSelected
);
531 * Add a tab for use in tabbed navigation mode. The tab will be inserted at
532 * <code>position</code>. If this is the first tab to be added it will become
535 * @param tab The tab to add
536 * @param position The new position of the tab
538 public abstract void addTab(Tab tab
, int position
);
541 * Add a tab for use in tabbed navigation mode. The tab will be insterted at
542 * <code>position</code>.
544 * @param tab The tab to add
545 * @param position The new position of the tab
546 * @param setSelected True if the added tab should become the selected tab.
548 public abstract void addTab(Tab tab
, int position
, boolean setSelected
);
551 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
552 * and another tab will be selected if present.
554 * @param tab The tab to remove
556 public abstract void removeTab(Tab tab
);
559 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
560 * and another tab will be selected if present.
562 * @param position Position of the tab to remove
564 public abstract void removeTabAt(int position
);
567 * Remove all tabs from the action bar and deselect the current tab.
569 public abstract void removeAllTabs();
572 * Select the specified tab. If it is not a child of this action bar it will be added.
574 * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
576 * @param tab Tab to select
578 public abstract void selectTab(Tab tab
);
581 * Returns the currently selected tab if in tabbed navigation mode and there is at least
584 * @return The currently selected tab or null
586 public abstract Tab
getSelectedTab();
589 * Returns the tab at the specified index.
591 * @param index Index value in the range 0-get
594 public abstract Tab
getTabAt(int index
);
597 * Returns the number of tabs currently registered with the action bar.
600 public abstract int getTabCount();
603 * Retrieve the current height of the ActionBar.
605 * @return The ActionBar's height
607 public abstract int getHeight();
610 * Show the ActionBar if it is not currently showing.
611 * If the window hosting the ActionBar does not have the feature
612 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
613 * content to fit the new space available.
615 public abstract void show();
618 * Hide the ActionBar if it is currently showing.
619 * If the window hosting the ActionBar does not have the feature
620 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
621 * content to fit the new space available.
623 public abstract void hide();
626 * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
628 public abstract boolean isShowing();
631 * Add a listener that will respond to menu visibility change events.
633 * @param listener The new listener to add
635 public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener
);
638 * Remove a menu visibility listener. This listener will no longer receive menu
639 * visibility change events.
641 * @param listener A listener to remove that was previously added
643 public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener
);
646 * Enable or disable the "home" button in the corner of the action bar. (Note that this
647 * is the application home/up affordance on the action bar, not the systemwide home
650 * <p>This defaults to true for packages targeting < API 14. For packages targeting
651 * API 14 or greater, the application should call this method to enable interaction
652 * with the home/up affordance.
654 * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
657 * @param enabled true to enable the home button, false to disable the home button.
659 public void setHomeButtonEnabled(boolean enabled
) { }
662 * Returns a {@link Context} with an appropriate theme for creating views that
663 * will appear in the action bar. If you are inflating or instantiating custom views
664 * that will appear in an action bar, you should use the Context returned by this method.
665 * (This includes adapters used for list navigation mode.)
666 * This will ensure that views contrast properly against the action bar.
668 * @return A themed Context for creating views
670 public Context
getThemedContext() { return null
; }
673 * Listener interface for ActionBar navigation events.
675 public interface OnNavigationListener
{
677 * This method is called whenever a navigation item in your action bar
680 * @param itemPosition Position of the item clicked.
681 * @param itemId ID of the item clicked.
682 * @return True if the event was handled, false otherwise.
684 public boolean onNavigationItemSelected(int itemPosition
, long itemId
);
688 * Listener for receiving events when action bar menus are shown or hidden.
690 public interface OnMenuVisibilityListener
{
692 * Called when an action bar menu is shown or hidden. Applications may want to use
693 * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
694 * gameplay, or other activity within the main content area.
696 * @param isVisible True if an action bar menu is now visible, false if no action bar
699 public void onMenuVisibilityChanged(boolean isVisible
);
703 * A tab in the action bar.
705 * <p>Tabs manage the hiding and showing of {@link Fragment}s.
707 public static abstract class Tab
{
709 * An invalid position for a tab.
711 * @see #getPosition()
713 public static final int INVALID_POSITION
= -1;
716 * Return the current position of this tab in the action bar.
718 * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
721 public abstract int getPosition();
724 * Return the icon associated with this tab.
726 * @return The tab's icon
728 public abstract Drawable
getIcon();
731 * Return the text of this tab.
733 * @return The tab's text
735 public abstract CharSequence
getText();
738 * Set the icon displayed on this tab.
740 * @param icon The drawable to use as an icon
741 * @return The current instance for call chaining
743 public abstract Tab
setIcon(Drawable icon
);
746 * Set the icon displayed on this tab.
748 * @param resId Resource ID referring to the drawable to use as an icon
749 * @return The current instance for call chaining
751 public abstract Tab
setIcon(int resId
);
754 * Set the text displayed on this tab. Text may be truncated if there is not
755 * room to display the entire string.
757 * @param text The text to display
758 * @return The current instance for call chaining
760 public abstract Tab
setText(CharSequence text
);
763 * Set the text displayed on this tab. Text may be truncated if there is not
764 * room to display the entire string.
766 * @param resId A resource ID referring to the text that should be displayed
767 * @return The current instance for call chaining
769 public abstract Tab
setText(int resId
);
772 * Set a custom view to be used for this tab. This overrides values set by
773 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
775 * @param view Custom view to be used as a tab.
776 * @return The current instance for call chaining
778 public abstract Tab
setCustomView(View view
);
781 * Set a custom view to be used for this tab. This overrides values set by
782 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
784 * @param layoutResId A layout resource to inflate and use as a custom tab view
785 * @return The current instance for call chaining
787 public abstract Tab
setCustomView(int layoutResId
);
790 * Retrieve a previously set custom view for this tab.
792 * @return The custom view set by {@link #setCustomView(View)}.
794 public abstract View
getCustomView();
797 * Give this Tab an arbitrary object to hold for later use.
799 * @param obj Object to store
800 * @return The current instance for call chaining
802 public abstract Tab
setTag(Object obj
);
805 * @return This Tab's tag object.
807 public abstract Object
getTag();
810 * Set the {@link TabListener} that will handle switching to and from this tab.
811 * All tabs must have a TabListener set before being added to the ActionBar.
813 * @param listener Listener to handle tab selection events
814 * @return The current instance for call chaining
816 public abstract Tab
setTabListener(TabListener listener
);
819 * Select this tab. Only valid if the tab has been added to the action bar.
821 public abstract void select();
824 * Set a description of this tab's content for use in accessibility support.
825 * If no content description is provided the title will be used.
827 * @param resId A resource ID referring to the description text
828 * @return The current instance for call chaining
829 * @see #setContentDescription(CharSequence)
830 * @see #getContentDescription()
832 public abstract Tab
setContentDescription(int resId
);
835 * Set a description of this tab's content for use in accessibility support.
836 * If no content description is provided the title will be used.
838 * @param contentDesc Description of this tab's content
839 * @return The current instance for call chaining
840 * @see #setContentDescription(int)
841 * @see #getContentDescription()
843 public abstract Tab
setContentDescription(CharSequence contentDesc
);
846 * Gets a brief description of this tab's content for use in accessibility support.
848 * @return Description of this tab's content
849 * @see #setContentDescription(CharSequence)
850 * @see #setContentDescription(int)
852 public abstract CharSequence
getContentDescription();
856 * Callback interface invoked when a tab is focused, unfocused, added, or removed.
858 public interface TabListener
{
860 * Called when a tab enters the selected state.
862 * @param tab The tab that was selected
863 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
864 * during a tab switch. The previous tab's unselect and this tab's select will be
865 * executed in a single transaction. This FragmentTransaction does not support
866 * being added to the back stack.
868 public void onTabSelected(Tab tab
, FragmentTransaction ft
);
871 * Called when a tab exits the selected state.
873 * @param tab The tab that was unselected
874 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
875 * during a tab switch. This tab's unselect and the newly selected tab's select
876 * will be executed in a single transaction. This FragmentTransaction does not
877 * support being added to the back stack.
879 public void onTabUnselected(Tab tab
, FragmentTransaction ft
);
882 * Called when a tab that is already selected is chosen again by the user.
883 * Some applications may use this action to return to the top level of a category.
885 * @param tab The tab that was reselected.
886 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
887 * once this method returns. This FragmentTransaction does not support
888 * being added to the back stack.
890 public void onTabReselected(Tab tab
, FragmentTransaction ft
);
894 * Per-child layout information associated with action bar custom views.
896 * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
898 public static class LayoutParams
extends MarginLayoutParams
{
899 private static final int[] ATTRS
= new int[] {
900 android
.R
.attr
.layout_gravity
904 * Gravity for the view associated with these LayoutParams.
906 * @see android.view.Gravity
908 @ViewDebug.ExportedProperty(mapping
= {
909 @ViewDebug.IntToString(from
= -1, to
= "NONE"),
910 @ViewDebug.IntToString(from
= Gravity
.NO_GRAVITY
, to
= "NONE"),
911 @ViewDebug.IntToString(from
= Gravity
.TOP
, to
= "TOP"),
912 @ViewDebug.IntToString(from
= Gravity
.BOTTOM
, to
= "BOTTOM"),
913 @ViewDebug.IntToString(from
= Gravity
.LEFT
, to
= "LEFT"),
914 @ViewDebug.IntToString(from
= Gravity
.RIGHT
, to
= "RIGHT"),
915 @ViewDebug.IntToString(from
= Gravity
.CENTER_VERTICAL
, to
= "CENTER_VERTICAL"),
916 @ViewDebug.IntToString(from
= Gravity
.FILL_VERTICAL
, to
= "FILL_VERTICAL"),
917 @ViewDebug.IntToString(from
= Gravity
.CENTER_HORIZONTAL
, to
= "CENTER_HORIZONTAL"),
918 @ViewDebug.IntToString(from
= Gravity
.FILL_HORIZONTAL
, to
= "FILL_HORIZONTAL"),
919 @ViewDebug.IntToString(from
= Gravity
.CENTER
, to
= "CENTER"),
920 @ViewDebug.IntToString(from
= Gravity
.FILL
, to
= "FILL")
922 public int gravity
= -1;
924 public LayoutParams(Context c
, AttributeSet attrs
) {
927 TypedArray a
= c
.obtainStyledAttributes(attrs
, ATTRS
);
928 gravity
= a
.getInt(0, -1);
932 public LayoutParams(int width
, int height
) {
933 super(width
, height
);
934 this.gravity
= Gravity
.CENTER_VERTICAL
| Gravity
.LEFT
;
937 public LayoutParams(int width
, int height
, int gravity
) {
938 super(width
, height
);
939 this.gravity
= gravity
;
942 public LayoutParams(int gravity
) {
943 this(WRAP_CONTENT
, FILL_PARENT
, gravity
);
946 public LayoutParams(LayoutParams source
) {
949 this.gravity
= source
.gravity
;
952 public LayoutParams(ViewGroup
.LayoutParams source
) {