blob: 29c1c569aa81bf9bb700c3b39456a14481a354ba [file] [log] [blame]
Adam Powell33b97432010-04-20 10:01:14 -07001/*
2 * Copyright (C) 2010 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
17package android.app;
18
Tor Norbyed9273d62013-05-30 15:59:53 -070019import android.annotation.IntDef;
20import android.annotation.NonNull;
21import android.annotation.Nullable;
Adam Powell9ab97872010-10-26 21:47:29 -070022import android.content.Context;
23import android.content.res.TypedArray;
Adam Powell33b97432010-04-20 10:01:14 -070024import android.graphics.drawable.Drawable;
Adam Powell9ab97872010-10-26 21:47:29 -070025import android.util.AttributeSet;
26import android.view.Gravity;
Adam Powell33b97432010-04-20 10:01:14 -070027import android.view.View;
Adam Powell9ab97872010-10-26 21:47:29 -070028import android.view.ViewDebug;
29import android.view.ViewGroup;
30import android.view.ViewGroup.MarginLayoutParams;
Adam Powell6b336f82010-08-10 20:13:01 -070031import android.view.Window;
Adam Powella4082912010-06-04 18:34:02 -070032import android.widget.SpinnerAdapter;
Adam Powell33b97432010-04-20 10:01:14 -070033
Tor Norbyed9273d62013-05-30 15:59:53 -070034import java.lang.annotation.Retention;
35import java.lang.annotation.RetentionPolicy;
36
Adam Powell33b97432010-04-20 10:01:14 -070037/**
Scott Maine797ed62011-09-22 16:17:45 -070038 * A window feature at the top of the activity that may display the activity title, navigation
39 * modes, and other interactive items.
40 * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
41 * activity's window when the activity uses the system's {@link
42 * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default.
43 * You may otherwise add the action bar by calling {@link
44 * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a
45 * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property.
46 * <p>By default, the action bar shows the application icon on
47 * the left, followed by the activity title. If your activity has an options menu, you can make
48 * select items accessible directly from the action bar as "action items". You can also
49 * modify various characteristics of the action bar or remove it completely.</p>
Scott Main36193d02011-07-12 15:24:01 -070050 * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
51 * android.app.Activity#getActionBar getActionBar()}.</p>
Scott Maine797ed62011-09-22 16:17:45 -070052 * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions,
53 * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in
54 * your activity, you can enable an action mode that offers actions specific to the selected
55 * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the
56 * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for
57 * {@link ActionBar}.
Joe Fernandezb54e7a32011-10-03 15:09:50 -070058 * <div class="special reference">
59 * <h3>Developer Guides</h3>
60 * <p>For information about how to use the action bar, including how to add action items, navigation
61 * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action
62 * Bar</a> developer guide.</p>
63 * </div>
Adam Powell33b97432010-04-20 10:01:14 -070064 */
65public abstract class ActionBar {
Tor Norbyed9273d62013-05-30 15:59:53 -070066 /** @hide */
67 @Retention(RetentionPolicy.SOURCE)
68 @IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
69 public @interface NavigationMode {}
70
Adam Powella1700782010-05-13 13:27:35 -070071 /**
Adam Powella4082912010-06-04 18:34:02 -070072 * Standard navigation mode. Consists of either a logo or icon
Adam Powella1700782010-05-13 13:27:35 -070073 * and title text with an optional subtitle. Clicking any of these elements
Adam Powellcf035762010-12-06 11:49:45 -080074 * will dispatch onOptionsItemSelected to the host Activity with
Adam Powella1700782010-05-13 13:27:35 -070075 * a MenuItem with item ID android.R.id.home.
Adam Powellfc35dfd2014-03-17 17:44:59 -070076 *
77 * @deprecated Action bar navigation modes are deprecated and not supported by inline
78 * toolbar action bars. Consider using other
79 * <a href="http://developer.android.com/design/patterns/navigation.html">common
80 * navigation patterns</a> instead.
Adam Powella1700782010-05-13 13:27:35 -070081 */
Adam Powella4082912010-06-04 18:34:02 -070082 public static final int NAVIGATION_MODE_STANDARD = 0;
Adam Powell33b97432010-04-20 10:01:14 -070083
84 /**
Adam Powell9ab97872010-10-26 21:47:29 -070085 * List navigation mode. Instead of static title text this mode
86 * presents a list menu for navigation within the activity.
87 * e.g. this might be presented to the user as a dropdown list.
Adam Powellfc35dfd2014-03-17 17:44:59 -070088 *
89 * @deprecated Action bar navigation modes are deprecated and not supported by inline
90 * toolbar action bars. Consider using other
91 * <a href="http://developer.android.com/design/patterns/navigation.html">common
92 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -070093 */
Adam Powell9ab97872010-10-26 21:47:29 -070094 public static final int NAVIGATION_MODE_LIST = 1;
Adam Powell33b97432010-04-20 10:01:14 -070095
96 /**
97 * Tab navigation mode. Instead of static title text this mode
98 * presents a series of tabs for navigation within the activity.
Adam Powellfc35dfd2014-03-17 17:44:59 -070099 *
100 * @deprecated Action bar navigation modes are deprecated and not supported by inline
101 * toolbar action bars. Consider using other
102 * <a href="http://developer.android.com/design/patterns/navigation.html">common
103 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700104 */
105 public static final int NAVIGATION_MODE_TABS = 2;
Adam Powell33b97432010-04-20 10:01:14 -0700106
Tor Norbyed9273d62013-05-30 15:59:53 -0700107 /** @hide */
108 @Retention(RetentionPolicy.SOURCE)
109 @IntDef(flag = true,
110 value = {
111 DISPLAY_USE_LOGO,
112 DISPLAY_SHOW_HOME,
113 DISPLAY_HOME_AS_UP,
114 DISPLAY_SHOW_TITLE,
115 DISPLAY_SHOW_CUSTOM,
116 DISPLAY_TITLE_MULTIPLE_LINES
117 })
118 public @interface DisplayOptions {}
119
Adam Powell33b97432010-04-20 10:01:14 -0700120 /**
121 * Use logo instead of icon if available. This flag will cause appropriate
122 * navigation modes to use a wider logo in place of the standard icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700123 *
124 * @see #setDisplayOptions(int)
125 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700126 */
127 public static final int DISPLAY_USE_LOGO = 0x1;
128
129 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700130 * Show 'home' elements in this action bar, leaving more space for other
Adam Powell33b97432010-04-20 10:01:14 -0700131 * navigation elements. This includes logo and icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700132 *
133 * @see #setDisplayOptions(int)
134 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700135 */
Adam Powell9ab97872010-10-26 21:47:29 -0700136 public static final int DISPLAY_SHOW_HOME = 0x2;
137
138 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700139 * Display the 'home' element such that it appears as an 'up' affordance.
140 * e.g. show an arrow to the left indicating the action that will be taken.
141 *
142 * Set this flag if selecting the 'home' button in the action bar to return
143 * up by a single level in your UI rather than back to the top level or front page.
144 *
Adam Powellc29f4e52011-07-13 20:40:52 -0700145 * <p>Setting this option will implicitly enable interaction with the home/up
146 * button. See {@link #setHomeButtonEnabled(boolean)}.
147 *
Adam Powell9ab97872010-10-26 21:47:29 -0700148 * @see #setDisplayOptions(int)
149 * @see #setDisplayOptions(int, int)
150 */
151 public static final int DISPLAY_HOME_AS_UP = 0x4;
152
153 /**
154 * Show the activity title and subtitle, if present.
155 *
156 * @see #setTitle(CharSequence)
157 * @see #setTitle(int)
158 * @see #setSubtitle(CharSequence)
159 * @see #setSubtitle(int)
160 * @see #setDisplayOptions(int)
161 * @see #setDisplayOptions(int, int)
162 */
163 public static final int DISPLAY_SHOW_TITLE = 0x8;
164
165 /**
166 * Show the custom view if one has been set.
167 * @see #setCustomView(View)
168 * @see #setDisplayOptions(int)
169 * @see #setDisplayOptions(int, int)
170 */
171 public static final int DISPLAY_SHOW_CUSTOM = 0x10;
172
173 /**
Adam Powell27cba382013-01-22 18:55:20 -0800174 * Allow the title to wrap onto multiple lines if space is available
175 * @hide pending API approval
176 */
177 public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20;
178
179 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700180 * Set the action bar into custom navigation mode, supplying a view
181 * for custom navigation.
182 *
183 * Custom navigation views appear between the application icon and
184 * any action buttons and may use any space available there. Common
185 * use cases for custom navigation views might include an auto-suggesting
186 * address bar for a browser or other navigation mechanisms that do not
187 * translate well to provided navigation modes.
188 *
189 * @param view Custom navigation view to place in the ActionBar.
190 */
191 public abstract void setCustomView(View view);
Adam Powell89e06452010-06-23 20:24:52 -0700192
Adam Powell33b97432010-04-20 10:01:14 -0700193 /**
Adam Powella4082912010-06-04 18:34:02 -0700194 * Set the action bar into custom navigation mode, supplying a view
195 * for custom navigation.
Adam Powell33b97432010-04-20 10:01:14 -0700196 *
Adam Powellef704442010-11-16 14:48:22 -0800197 * <p>Custom navigation views appear between the application icon and
Adam Powell33b97432010-04-20 10:01:14 -0700198 * any action buttons and may use any space available there. Common
Adam Powella4082912010-06-04 18:34:02 -0700199 * use cases for custom navigation views might include an auto-suggesting
200 * address bar for a browser or other navigation mechanisms that do not
Adam Powellef704442010-11-16 14:48:22 -0800201 * translate well to provided navigation modes.</p>
202 *
203 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
204 * the custom view to be displayed.</p>
Adam Powell33b97432010-04-20 10:01:14 -0700205 *
206 * @param view Custom navigation view to place in the ActionBar.
Adam Powell9ab97872010-10-26 21:47:29 -0700207 * @param layoutParams How this custom view should layout in the bar.
Adam Powellef704442010-11-16 14:48:22 -0800208 *
209 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700210 */
Adam Powell9ab97872010-10-26 21:47:29 -0700211 public abstract void setCustomView(View view, LayoutParams layoutParams);
212
213 /**
Adam Powell3f476b32011-01-03 19:25:36 -0800214 * Set the action bar into custom navigation mode, supplying a view
215 * for custom navigation.
216 *
217 * <p>Custom navigation views appear between the application icon and
218 * any action buttons and may use any space available there. Common
219 * use cases for custom navigation views might include an auto-suggesting
220 * address bar for a browser or other navigation mechanisms that do not
221 * translate well to provided navigation modes.</p>
222 *
223 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
224 * the custom view to be displayed.</p>
225 *
226 * @param resId Resource ID of a layout to inflate into the ActionBar.
227 *
228 * @see #setDisplayOptions(int, int)
229 */
230 public abstract void setCustomView(int resId);
231
232 /**
Adam Powell1969b872011-03-22 11:52:48 -0700233 * Set the icon to display in the 'home' section of the action bar.
234 * The action bar will use an icon specified by its style or the
235 * activity icon by default.
236 *
237 * Whether the home section shows an icon or logo is controlled
238 * by the display option {@link #DISPLAY_USE_LOGO}.
239 *
240 * @param resId Resource ID of a drawable to show as an icon.
241 *
242 * @see #setDisplayUseLogoEnabled(boolean)
243 * @see #setDisplayShowHomeEnabled(boolean)
244 */
245 public abstract void setIcon(int resId);
246
247 /**
248 * Set the icon to display in the 'home' section of the action bar.
249 * The action bar will use an icon specified by its style or the
250 * activity icon by default.
251 *
252 * Whether the home section shows an icon or logo is controlled
253 * by the display option {@link #DISPLAY_USE_LOGO}.
254 *
255 * @param icon Drawable to show as an icon.
256 *
257 * @see #setDisplayUseLogoEnabled(boolean)
258 * @see #setDisplayShowHomeEnabled(boolean)
259 */
260 public abstract void setIcon(Drawable icon);
261
262 /**
263 * Set the logo to display in the 'home' section of the action bar.
264 * The action bar will use a logo specified by its style or the
265 * activity logo by default.
266 *
267 * Whether the home section shows an icon or logo is controlled
268 * by the display option {@link #DISPLAY_USE_LOGO}.
269 *
270 * @param resId Resource ID of a drawable to show as a logo.
271 *
272 * @see #setDisplayUseLogoEnabled(boolean)
273 * @see #setDisplayShowHomeEnabled(boolean)
274 */
275 public abstract void setLogo(int resId);
276
277 /**
278 * Set the logo to display in the 'home' section of the action bar.
279 * The action bar will use a logo specified by its style or the
280 * activity logo by default.
281 *
282 * Whether the home section shows an icon or logo is controlled
283 * by the display option {@link #DISPLAY_USE_LOGO}.
284 *
285 * @param logo Drawable to show as a logo.
286 *
287 * @see #setDisplayUseLogoEnabled(boolean)
288 * @see #setDisplayShowHomeEnabled(boolean)
289 */
290 public abstract void setLogo(Drawable logo);
291
292 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700293 * Set the adapter and navigation callback for list navigation mode.
294 *
295 * The supplied adapter will provide views for the expanded list as well as
296 * the currently selected item. (These may be displayed differently.)
297 *
Adam Powell8515ee82010-11-30 14:09:55 -0800298 * The supplied OnNavigationListener will alert the application when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700299 * changes the current list selection.
300 *
301 * @param adapter An adapter that will provide views both to display
302 * the current navigation selection and populate views
303 * within the dropdown navigation menu.
Adam Powell8515ee82010-11-30 14:09:55 -0800304 * @param callback An OnNavigationListener that will receive events when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700305 * selects a navigation item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700306 *
307 * @deprecated Action bar navigation modes are deprecated and not supported by inline
308 * toolbar action bars. Consider using other
309 * <a href="http://developer.android.com/design/patterns/navigation.html">common
310 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700311 */
312 public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
Adam Powell8515ee82010-11-30 14:09:55 -0800313 OnNavigationListener callback);
Adam Powell9ab97872010-10-26 21:47:29 -0700314
315 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700316 * Set the selected navigation item in list or tabbed navigation modes.
Adam Powell17809772010-07-21 13:25:11 -0700317 *
318 * @param position Position of the item to select.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700319 *
320 * @deprecated Action bar navigation modes are deprecated and not supported by inline
321 * toolbar action bars. Consider using other
322 * <a href="http://developer.android.com/design/patterns/navigation.html">common
323 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700324 */
325 public abstract void setSelectedNavigationItem(int position);
326
327 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700328 * Get the position of the selected navigation item in list or tabbed navigation modes.
329 *
330 * @return Position of the selected item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700331 *
332 * @deprecated Action bar navigation modes are deprecated and not supported by inline
333 * toolbar action bars. Consider using other
334 * <a href="http://developer.android.com/design/patterns/navigation.html">common
335 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700336 */
Adam Powell9ab97872010-10-26 21:47:29 -0700337 public abstract int getSelectedNavigationIndex();
338
339 /**
340 * Get the number of navigation items present in the current navigation mode.
341 *
342 * @return Number of navigation items.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700343 *
344 * @deprecated Action bar navigation modes are deprecated and not supported by inline
345 * toolbar action bars. Consider using other
346 * <a href="http://developer.android.com/design/patterns/navigation.html">common
347 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700348 */
349 public abstract int getNavigationItemCount();
Adam Powell17809772010-07-21 13:25:11 -0700350
351 /**
Adam Powellef704442010-11-16 14:48:22 -0800352 * Set the action bar's title. This will only be displayed if
353 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powell0e94b512010-06-29 17:58:20 -0700354 *
355 * @param title Title to set
Adam Powella66c7b02010-07-28 15:28:25 -0700356 *
357 * @see #setTitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800358 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700359 */
360 public abstract void setTitle(CharSequence title);
361
362 /**
Adam Powellef704442010-11-16 14:48:22 -0800363 * Set the action bar's title. This will only be displayed if
364 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700365 *
366 * @param resId Resource ID of title string to set
367 *
368 * @see #setTitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800369 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700370 */
371 public abstract void setTitle(int resId);
372
373 /**
Adam Powellef704442010-11-16 14:48:22 -0800374 * Set the action bar's subtitle. This will only be displayed if
375 * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
376 * subtitle entirely.
Adam Powell0e94b512010-06-29 17:58:20 -0700377 *
378 * @param subtitle Subtitle to set
Adam Powella66c7b02010-07-28 15:28:25 -0700379 *
380 * @see #setSubtitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800381 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700382 */
383 public abstract void setSubtitle(CharSequence subtitle);
384
385 /**
Adam Powellef704442010-11-16 14:48:22 -0800386 * Set the action bar's subtitle. This will only be displayed if
387 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700388 *
389 * @param resId Resource ID of subtitle string to set
390 *
391 * @see #setSubtitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800392 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700393 */
394 public abstract void setSubtitle(int resId);
395
396 /**
Adam Powella1700782010-05-13 13:27:35 -0700397 * Set display options. This changes all display option bits at once. To change
398 * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
Adam Powell33b97432010-04-20 10:01:14 -0700399 *
400 * @param options A combination of the bits defined by the DISPLAY_ constants
401 * defined in ActionBar.
402 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700403 public abstract void setDisplayOptions(@DisplayOptions int options);
Adam Powell33b97432010-04-20 10:01:14 -0700404
405 /**
Adam Powella1700782010-05-13 13:27:35 -0700406 * Set selected display options. Only the options specified by mask will be changed.
407 * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
408 *
Adam Powell9ab97872010-10-26 21:47:29 -0700409 * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
410 * {@link #DISPLAY_SHOW_HOME} option.
Ben Komalo5ad7af62010-11-01 12:04:51 -0700411 * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
Adam Powell9ab97872010-10-26 21:47:29 -0700412 * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
Adam Powella1700782010-05-13 13:27:35 -0700413 *
414 * @param options A combination of the bits defined by the DISPLAY_ constants
415 * defined in ActionBar.
416 * @param mask A bit mask declaring which display options should be changed.
417 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700418 public abstract void setDisplayOptions(@DisplayOptions int options, @DisplayOptions int mask);
Adam Powell3f476b32011-01-03 19:25:36 -0800419
420 /**
421 * Set whether to display the activity logo rather than the activity icon.
422 * A logo is often a wider, more detailed image.
423 *
424 * <p>To set several display options at once, see the setDisplayOptions methods.
425 *
426 * @param useLogo true to use the activity logo, false to use the activity icon.
427 *
428 * @see #setDisplayOptions(int)
429 * @see #setDisplayOptions(int, int)
430 */
431 public abstract void setDisplayUseLogoEnabled(boolean useLogo);
432
433 /**
434 * Set whether to include the application home affordance in the action bar.
435 * Home is presented as either an activity icon or logo.
436 *
437 * <p>To set several display options at once, see the setDisplayOptions methods.
438 *
439 * @param showHome true to show home, false otherwise.
440 *
441 * @see #setDisplayOptions(int)
442 * @see #setDisplayOptions(int, int)
443 */
444 public abstract void setDisplayShowHomeEnabled(boolean showHome);
445
446 /**
447 * Set whether home should be displayed as an "up" affordance.
448 * Set this to true if selecting "home" returns up by a single level in your UI
449 * rather than back to the top level or front page.
450 *
451 * <p>To set several display options at once, see the setDisplayOptions methods.
452 *
453 * @param showHomeAsUp true to show the user that selecting home will return one
454 * level up rather than to the top level of the app.
455 *
456 * @see #setDisplayOptions(int)
457 * @see #setDisplayOptions(int, int)
458 */
459 public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
460
461 /**
462 * Set whether an activity title/subtitle should be displayed.
463 *
464 * <p>To set several display options at once, see the setDisplayOptions methods.
465 *
466 * @param showTitle true to display a title/subtitle if present.
467 *
468 * @see #setDisplayOptions(int)
469 * @see #setDisplayOptions(int, int)
470 */
471 public abstract void setDisplayShowTitleEnabled(boolean showTitle);
472
473 /**
474 * Set whether a custom view should be displayed, if set.
475 *
476 * <p>To set several display options at once, see the setDisplayOptions methods.
477 *
478 * @param showCustom true if the currently set custom view should be displayed, false otherwise.
479 *
480 * @see #setDisplayOptions(int)
481 * @see #setDisplayOptions(int, int)
482 */
483 public abstract void setDisplayShowCustomEnabled(boolean showCustom);
484
Adam Powella1700782010-05-13 13:27:35 -0700485 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700486 * Set the ActionBar's background. This will be used for the primary
487 * action bar.
Adam Powell33b97432010-04-20 10:01:14 -0700488 *
489 * @param d Background drawable
Adam Powellf88b9152011-09-07 14:54:32 -0700490 * @see #setStackedBackgroundDrawable(Drawable)
491 * @see #setSplitBackgroundDrawable(Drawable)
Adam Powell33b97432010-04-20 10:01:14 -0700492 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700493 public abstract void setBackgroundDrawable(@Nullable Drawable d);
Adam Powellef704442010-11-16 14:48:22 -0800494
495 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700496 * Set the ActionBar's stacked background. This will appear
497 * in the second row/stacked bar on some devices and configurations.
498 *
499 * @param d Background drawable for the stacked row
500 */
Adam Powell01453222011-09-07 16:13:36 -0700501 public void setStackedBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700502
503 /**
504 * Set the ActionBar's split background. This will appear in
505 * the split action bar containing menu-provided action buttons
506 * on some devices and configurations.
Scott Maine797ed62011-09-22 16:17:45 -0700507 * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
Adam Powellf88b9152011-09-07 14:54:32 -0700508 *
509 * @param d Background drawable for the split bar
510 */
Adam Powell01453222011-09-07 16:13:36 -0700511 public void setSplitBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700512
513 /**
Adam Powellef704442010-11-16 14:48:22 -0800514 * @return The current custom view.
515 */
516 public abstract View getCustomView();
517
Adam Powell33b97432010-04-20 10:01:14 -0700518 /**
Adam Powella4082912010-06-04 18:34:02 -0700519 * Returns the current ActionBar title in standard mode.
520 * Returns null if {@link #getNavigationMode()} would not return
521 * {@link #NAVIGATION_MODE_STANDARD}.
522 *
523 * @return The current ActionBar title or null.
Adam Powell33b97432010-04-20 10:01:14 -0700524 */
525 public abstract CharSequence getTitle();
526
527 /**
Adam Powella4082912010-06-04 18:34:02 -0700528 * Returns the current ActionBar subtitle in standard mode.
529 * Returns null if {@link #getNavigationMode()} would not return
530 * {@link #NAVIGATION_MODE_STANDARD}.
531 *
532 * @return The current ActionBar subtitle or null.
Adam Powell33b97432010-04-20 10:01:14 -0700533 */
534 public abstract CharSequence getSubtitle();
535
536 /**
Adam Powella4082912010-06-04 18:34:02 -0700537 * Returns the current navigation mode. The result will be one of:
538 * <ul>
539 * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
Adam Powell9ab97872010-10-26 21:47:29 -0700540 * <li>{@link #NAVIGATION_MODE_LIST}</li>
Adam Powella4082912010-06-04 18:34:02 -0700541 * <li>{@link #NAVIGATION_MODE_TABS}</li>
Adam Powella4082912010-06-04 18:34:02 -0700542 * </ul>
543 *
Adam Powell33b97432010-04-20 10:01:14 -0700544 * @return The current navigation mode.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700545 *
546 * @deprecated Action bar navigation modes are deprecated and not supported by inline
547 * toolbar action bars. Consider using other
548 * <a href="http://developer.android.com/design/patterns/navigation.html">common
549 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700550 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700551 @NavigationMode
Adam Powell33b97432010-04-20 10:01:14 -0700552 public abstract int getNavigationMode();
Adam Powell9ab97872010-10-26 21:47:29 -0700553
554 /**
555 * Set the current navigation mode.
556 *
557 * @param mode The new mode to set.
558 * @see #NAVIGATION_MODE_STANDARD
559 * @see #NAVIGATION_MODE_LIST
560 * @see #NAVIGATION_MODE_TABS
Adam Powellfc35dfd2014-03-17 17:44:59 -0700561 *
562 * @deprecated Action bar navigation modes are deprecated and not supported by inline
563 * toolbar action bars. Consider using other
564 * <a href="http://developer.android.com/design/patterns/navigation.html">common
565 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700566 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700567 public abstract void setNavigationMode(@NavigationMode int mode);
Adam Powell9ab97872010-10-26 21:47:29 -0700568
Adam Powell33b97432010-04-20 10:01:14 -0700569 /**
570 * @return The current set of display options.
571 */
572 public abstract int getDisplayOptions();
Adam Powell661c9082010-07-02 10:09:44 -0700573
574 /**
Adam Powell661c9082010-07-02 10:09:44 -0700575 * Create and return a new {@link Tab}.
576 * This tab will not be included in the action bar until it is added.
577 *
Dianne Hackborn2f048832011-06-16 13:31:57 -0700578 * <p>Very often tabs will be used to switch between {@link Fragment}
579 * objects. Here is a typical implementation of such tabs:</p>
580 *
581 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
582 * complete}
583 *
Adam Powell661c9082010-07-02 10:09:44 -0700584 * @return A new Tab
585 *
586 * @see #addTab(Tab)
Adam Powellfc35dfd2014-03-17 17:44:59 -0700587 *
588 * @deprecated Action bar navigation modes are deprecated and not supported by inline
589 * toolbar action bars. Consider using other
590 * <a href="http://developer.android.com/design/patterns/navigation.html">common
591 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700592 */
593 public abstract Tab newTab();
594
595 /**
596 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
Adam Powell81b89442010-11-02 17:58:56 -0700597 * If this is the first tab to be added it will become the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700598 *
599 * @param tab Tab to add
Adam Powellfc35dfd2014-03-17 17:44:59 -0700600 *
601 * @deprecated Action bar navigation modes are deprecated and not supported by inline
602 * toolbar action bars. Consider using other
603 * <a href="http://developer.android.com/design/patterns/navigation.html">common
604 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700605 */
606 public abstract void addTab(Tab tab);
607
608 /**
Adam Powell81b89442010-11-02 17:58:56 -0700609 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
610 *
611 * @param tab Tab to add
612 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700613 *
614 * @deprecated Action bar navigation modes are deprecated and not supported by inline
615 * toolbar action bars. Consider using other
616 * <a href="http://developer.android.com/design/patterns/navigation.html">common
617 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700618 */
619 public abstract void addTab(Tab tab, boolean setSelected);
620
621 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700622 * Add a tab for use in tabbed navigation mode. The tab will be inserted at
Adam Powell81b89442010-11-02 17:58:56 -0700623 * <code>position</code>. If this is the first tab to be added it will become
624 * the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700625 *
626 * @param tab The tab to add
627 * @param position The new position of the tab
Adam Powellfc35dfd2014-03-17 17:44:59 -0700628 *
629 * @deprecated Action bar navigation modes are deprecated and not supported by inline
630 * toolbar action bars. Consider using other
631 * <a href="http://developer.android.com/design/patterns/navigation.html">common
632 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700633 */
Adam Powell2b6230e2010-09-07 17:55:25 -0700634 public abstract void addTab(Tab tab, int position);
Adam Powell661c9082010-07-02 10:09:44 -0700635
636 /**
Adam Powell81b89442010-11-02 17:58:56 -0700637 * Add a tab for use in tabbed navigation mode. The tab will be insterted at
638 * <code>position</code>.
639 *
640 * @param tab The tab to add
641 * @param position The new position of the tab
642 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700643 *
644 * @deprecated Action bar navigation modes are deprecated and not supported by inline
645 * toolbar action bars. Consider using other
646 * <a href="http://developer.android.com/design/patterns/navigation.html">common
647 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700648 */
649 public abstract void addTab(Tab tab, int position, boolean setSelected);
650
651 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700652 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
653 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700654 *
655 * @param tab The tab to remove
Adam Powellfc35dfd2014-03-17 17:44:59 -0700656 *
657 * @deprecated Action bar navigation modes are deprecated and not supported by inline
658 * toolbar action bars. Consider using other
659 * <a href="http://developer.android.com/design/patterns/navigation.html">common
660 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700661 */
662 public abstract void removeTab(Tab tab);
663
664 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700665 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
666 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700667 *
668 * @param position Position of the tab to remove
Adam Powellfc35dfd2014-03-17 17:44:59 -0700669 *
670 * @deprecated Action bar navigation modes are deprecated and not supported by inline
671 * toolbar action bars. Consider using other
672 * <a href="http://developer.android.com/design/patterns/navigation.html">common
673 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700674 */
675 public abstract void removeTabAt(int position);
676
677 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700678 * Remove all tabs from the action bar and deselect the current tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700679 *
680 * @deprecated Action bar navigation modes are deprecated and not supported by inline
681 * toolbar action bars. Consider using other
682 * <a href="http://developer.android.com/design/patterns/navigation.html">common
683 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700684 */
685 public abstract void removeAllTabs();
686
687 /**
Adam Powell661c9082010-07-02 10:09:44 -0700688 * Select the specified tab. If it is not a child of this action bar it will be added.
689 *
Adam Powell9ab97872010-10-26 21:47:29 -0700690 * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
691 *
Adam Powell661c9082010-07-02 10:09:44 -0700692 * @param tab Tab to select
Adam Powellfc35dfd2014-03-17 17:44:59 -0700693 *
694 * @deprecated Action bar navigation modes are deprecated and not supported by inline
695 * toolbar action bars. Consider using other
696 * <a href="http://developer.android.com/design/patterns/navigation.html">common
697 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700698 */
699 public abstract void selectTab(Tab tab);
700
701 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700702 * Returns the currently selected tab if in tabbed navigation mode and there is at least
703 * one tab present.
704 *
705 * @return The currently selected tab or null
Adam Powellfc35dfd2014-03-17 17:44:59 -0700706 *
707 * @deprecated Action bar navigation modes are deprecated and not supported by inline
708 * toolbar action bars. Consider using other
709 * <a href="http://developer.android.com/design/patterns/navigation.html">common
710 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -0700711 */
712 public abstract Tab getSelectedTab();
713
714 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700715 * Returns the tab at the specified index.
716 *
717 * @param index Index value in the range 0-get
718 * @return
Adam Powellfc35dfd2014-03-17 17:44:59 -0700719 *
720 * @deprecated Action bar navigation modes are deprecated and not supported by inline
721 * toolbar action bars. Consider using other
722 * <a href="http://developer.android.com/design/patterns/navigation.html">common
723 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700724 */
725 public abstract Tab getTabAt(int index);
726
727 /**
Adam Powell0c24a552010-11-03 16:44:11 -0700728 * Returns the number of tabs currently registered with the action bar.
729 * @return Tab count
Adam Powellfc35dfd2014-03-17 17:44:59 -0700730 *
731 * @deprecated Action bar navigation modes are deprecated and not supported by inline
732 * toolbar action bars. Consider using other
733 * <a href="http://developer.android.com/design/patterns/navigation.html">common
734 * navigation patterns</a> instead.
Adam Powell0c24a552010-11-03 16:44:11 -0700735 */
736 public abstract int getTabCount();
737
738 /**
Adam Powell6b336f82010-08-10 20:13:01 -0700739 * Retrieve the current height of the ActionBar.
740 *
741 * @return The ActionBar's height
742 */
743 public abstract int getHeight();
744
745 /**
746 * Show the ActionBar if it is not currently showing.
747 * If the window hosting the ActionBar does not have the feature
748 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
749 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700750 *
751 * <p>If you are hiding the ActionBar through
752 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN},
753 * you should not call this function directly.
Adam Powell6b336f82010-08-10 20:13:01 -0700754 */
755 public abstract void show();
756
757 /**
Scott Maine797ed62011-09-22 16:17:45 -0700758 * Hide the ActionBar if it is currently showing.
Adam Powell6b336f82010-08-10 20:13:01 -0700759 * If the window hosting the ActionBar does not have the feature
760 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
761 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700762 *
763 * <p>Instead of calling this function directly, you can also cause an
764 * ActionBar using the overlay feature to hide through
765 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}.
766 * Hiding the ActionBar through this system UI flag allows you to more
767 * seamlessly hide it in conjunction with other screen decorations.
Adam Powell6b336f82010-08-10 20:13:01 -0700768 */
769 public abstract void hide();
770
771 /**
772 * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
773 */
774 public abstract boolean isShowing();
775
776 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800777 * Add a listener that will respond to menu visibility change events.
778 *
779 * @param listener The new listener to add
Adam Powell89e06452010-06-23 20:24:52 -0700780 */
Adam Powell8515ee82010-11-30 14:09:55 -0800781 public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
782
783 /**
784 * Remove a menu visibility listener. This listener will no longer receive menu
785 * visibility change events.
786 *
787 * @param listener A listener to remove that was previously added
788 */
789 public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
790
791 /**
Adam Powellc29f4e52011-07-13 20:40:52 -0700792 * Enable or disable the "home" button in the corner of the action bar. (Note that this
793 * is the application home/up affordance on the action bar, not the systemwide home
794 * button.)
795 *
796 * <p>This defaults to true for packages targeting &lt; API 14. For packages targeting
797 * API 14 or greater, the application should call this method to enable interaction
798 * with the home/up affordance.
799 *
800 * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
801 * the home button.
802 *
803 * @param enabled true to enable the home button, false to disable the home button.
804 */
Adam Powell88ab6972011-07-28 11:25:01 -0700805 public void setHomeButtonEnabled(boolean enabled) { }
806
807 /**
808 * Returns a {@link Context} with an appropriate theme for creating views that
809 * will appear in the action bar. If you are inflating or instantiating custom views
810 * that will appear in an action bar, you should use the Context returned by this method.
811 * (This includes adapters used for list navigation mode.)
812 * This will ensure that views contrast properly against the action bar.
813 *
814 * @return A themed Context for creating views
815 */
816 public Context getThemedContext() { return null; }
Adam Powellc29f4e52011-07-13 20:40:52 -0700817
818 /**
Adam Powell27cba382013-01-22 18:55:20 -0800819 * Returns true if the Title field has been truncated during layout for lack
820 * of available space.
821 *
822 * @return true if the Title field has been truncated
823 * @hide pending API approval
824 */
825 public boolean isTitleTruncated() { return false; }
826
827 /**
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700828 * Set an alternate drawable to display next to the icon/logo/title
829 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
830 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
831 *
832 * <p>If you pass <code>null</code> to this method, the default drawable from the theme
833 * will be used.</p>
834 *
835 * <p>If you implement alternate or intermediate behavior around Up, you should also
836 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
837 * to provide a correct description of the action for accessibility support.</p>
838 *
839 * @param indicator A drawable to use for the up indicator, or null to use the theme's default
840 *
841 * @see #setDisplayOptions(int, int)
842 * @see #setDisplayHomeAsUpEnabled(boolean)
843 * @see #setHomeActionContentDescription(int)
844 */
845 public void setHomeAsUpIndicator(Drawable indicator) { }
846
847 /**
848 * Set an alternate drawable to display next to the icon/logo/title
849 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
850 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
851 *
852 * <p>If you pass <code>0</code> to this method, the default drawable from the theme
853 * will be used.</p>
854 *
855 * <p>If you implement alternate or intermediate behavior around Up, you should also
856 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
857 * to provide a correct description of the action for accessibility support.</p>
858 *
859 * @param resId Resource ID of a drawable to use for the up indicator, or null
860 * to use the theme's default
861 *
862 * @see #setDisplayOptions(int, int)
863 * @see #setDisplayHomeAsUpEnabled(boolean)
864 * @see #setHomeActionContentDescription(int)
865 */
866 public void setHomeAsUpIndicator(int resId) { }
867
868 /**
869 * Set an alternate description for the Home/Up action, when enabled.
870 *
871 * <p>This description is commonly used for accessibility/screen readers when
872 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
873 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
874 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
875 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
876 * functionality such as a sliding drawer, you should also set this to accurately
877 * describe the action.</p>
878 *
879 * <p>Setting this to <code>null</code> will use the system default description.</p>
880 *
881 * @param description New description for the Home action when enabled
882 * @see #setHomeAsUpIndicator(int)
883 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
884 */
885 public void setHomeActionContentDescription(CharSequence description) { }
886
887 /**
888 * Set an alternate description for the Home/Up action, when enabled.
889 *
890 * <p>This description is commonly used for accessibility/screen readers when
891 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
892 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
893 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
894 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
895 * functionality such as a sliding drawer, you should also set this to accurately
896 * describe the action.</p>
897 *
898 * <p>Setting this to <code>0</code> will use the system default description.</p>
899 *
900 * @param resId Resource ID of a string to use as the new description
901 * for the Home action when enabled
902 * @see #setHomeAsUpIndicator(int)
903 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
904 */
905 public void setHomeActionContentDescription(int resId) { }
906
907 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800908 * Listener interface for ActionBar navigation events.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700909 *
910 * @deprecated Action bar navigation modes are deprecated and not supported by inline
911 * toolbar action bars. Consider using other
912 * <a href="http://developer.android.com/design/patterns/navigation.html">common
913 * navigation patterns</a> instead.
Adam Powell8515ee82010-11-30 14:09:55 -0800914 */
915 public interface OnNavigationListener {
Adam Powell33b97432010-04-20 10:01:14 -0700916 /**
Adam Powella4082912010-06-04 18:34:02 -0700917 * This method is called whenever a navigation item in your action bar
918 * is selected.
919 *
920 * @param itemPosition Position of the item clicked.
921 * @param itemId ID of the item clicked.
922 * @return True if the event was handled, false otherwise.
923 */
924 public boolean onNavigationItemSelected(int itemPosition, long itemId);
Adam Powell33b97432010-04-20 10:01:14 -0700925 }
Adam Powell661c9082010-07-02 10:09:44 -0700926
927 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800928 * Listener for receiving events when action bar menus are shown or hidden.
929 */
930 public interface OnMenuVisibilityListener {
931 /**
932 * Called when an action bar menu is shown or hidden. Applications may want to use
933 * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
934 * gameplay, or other activity within the main content area.
935 *
936 * @param isVisible True if an action bar menu is now visible, false if no action bar
937 * menus are visible.
938 */
939 public void onMenuVisibilityChanged(boolean isVisible);
940 }
941
942 /**
Adam Powell661c9082010-07-02 10:09:44 -0700943 * A tab in the action bar.
944 *
945 * <p>Tabs manage the hiding and showing of {@link Fragment}s.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700946 *
947 * @deprecated Action bar navigation modes are deprecated and not supported by inline
948 * toolbar action bars. Consider using other
949 * <a href="http://developer.android.com/design/patterns/navigation.html">common
950 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700951 */
952 public static abstract class Tab {
953 /**
954 * An invalid position for a tab.
955 *
956 * @see #getPosition()
957 */
958 public static final int INVALID_POSITION = -1;
959
960 /**
961 * Return the current position of this tab in the action bar.
962 *
963 * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
964 * the action bar.
965 */
966 public abstract int getPosition();
967
968 /**
969 * Return the icon associated with this tab.
970 *
971 * @return The tab's icon
972 */
973 public abstract Drawable getIcon();
974
975 /**
976 * Return the text of this tab.
977 *
978 * @return The tab's text
979 */
980 public abstract CharSequence getText();
981
982 /**
983 * Set the icon displayed on this tab.
984 *
985 * @param icon The drawable to use as an icon
Adam Powell9ab97872010-10-26 21:47:29 -0700986 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -0700987 */
Adam Powell9ab97872010-10-26 21:47:29 -0700988 public abstract Tab setIcon(Drawable icon);
Adam Powell661c9082010-07-02 10:09:44 -0700989
990 /**
Adam Powell32555f32010-11-17 13:49:22 -0800991 * Set the icon displayed on this tab.
992 *
993 * @param resId Resource ID referring to the drawable to use as an icon
994 * @return The current instance for call chaining
995 */
996 public abstract Tab setIcon(int resId);
997
998 /**
Adam Powell661c9082010-07-02 10:09:44 -0700999 * Set the text displayed on this tab. Text may be truncated if there is not
1000 * room to display the entire string.
1001 *
1002 * @param text The text to display
Adam Powell9ab97872010-10-26 21:47:29 -07001003 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001004 */
Adam Powell9ab97872010-10-26 21:47:29 -07001005 public abstract Tab setText(CharSequence text);
Adam Powell661c9082010-07-02 10:09:44 -07001006
1007 /**
Adam Powell32555f32010-11-17 13:49:22 -08001008 * Set the text displayed on this tab. Text may be truncated if there is not
1009 * room to display the entire string.
1010 *
1011 * @param resId A resource ID referring to the text that should be displayed
1012 * @return The current instance for call chaining
1013 */
1014 public abstract Tab setText(int resId);
1015
1016 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001017 * Set a custom view to be used for this tab. This overrides values set by
1018 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
Adam Powell661c9082010-07-02 10:09:44 -07001019 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001020 * @param view Custom view to be used as a tab.
Adam Powell9ab97872010-10-26 21:47:29 -07001021 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001022 */
Adam Powell9ab97872010-10-26 21:47:29 -07001023 public abstract Tab setCustomView(View view);
Adam Powell661c9082010-07-02 10:09:44 -07001024
1025 /**
Adam Powell32555f32010-11-17 13:49:22 -08001026 * Set a custom view to be used for this tab. This overrides values set by
1027 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
1028 *
1029 * @param layoutResId A layout resource to inflate and use as a custom tab view
1030 * @return The current instance for call chaining
1031 */
1032 public abstract Tab setCustomView(int layoutResId);
1033
1034 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001035 * Retrieve a previously set custom view for this tab.
Adam Powell661c9082010-07-02 10:09:44 -07001036 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001037 * @return The custom view set by {@link #setCustomView(View)}.
Adam Powell661c9082010-07-02 10:09:44 -07001038 */
Adam Powell2b6230e2010-09-07 17:55:25 -07001039 public abstract View getCustomView();
1040
1041 /**
1042 * Give this Tab an arbitrary object to hold for later use.
1043 *
1044 * @param obj Object to store
Adam Powell9ab97872010-10-26 21:47:29 -07001045 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001046 */
Adam Powell9ab97872010-10-26 21:47:29 -07001047 public abstract Tab setTag(Object obj);
Adam Powell2b6230e2010-09-07 17:55:25 -07001048
1049 /**
1050 * @return This Tab's tag object.
1051 */
1052 public abstract Object getTag();
1053
1054 /**
1055 * Set the {@link TabListener} that will handle switching to and from this tab.
1056 * All tabs must have a TabListener set before being added to the ActionBar.
1057 *
1058 * @param listener Listener to handle tab selection events
Adam Powell9ab97872010-10-26 21:47:29 -07001059 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001060 */
Adam Powell9ab97872010-10-26 21:47:29 -07001061 public abstract Tab setTabListener(TabListener listener);
Adam Powell661c9082010-07-02 10:09:44 -07001062
1063 /**
1064 * Select this tab. Only valid if the tab has been added to the action bar.
1065 */
1066 public abstract void select();
Adam Powell94e56ef2011-09-06 21:22:22 -07001067
1068 /**
1069 * Set a description of this tab's content for use in accessibility support.
1070 * If no content description is provided the title will be used.
1071 *
1072 * @param resId A resource ID referring to the description text
1073 * @return The current instance for call chaining
1074 * @see #setContentDescription(CharSequence)
1075 * @see #getContentDescription()
1076 */
1077 public abstract Tab setContentDescription(int resId);
1078
1079 /**
1080 * Set a description of this tab's content for use in accessibility support.
1081 * If no content description is provided the title will be used.
1082 *
1083 * @param contentDesc Description of this tab's content
1084 * @return The current instance for call chaining
1085 * @see #setContentDescription(int)
1086 * @see #getContentDescription()
1087 */
1088 public abstract Tab setContentDescription(CharSequence contentDesc);
1089
1090 /**
1091 * Gets a brief description of this tab's content for use in accessibility support.
1092 *
1093 * @return Description of this tab's content
1094 * @see #setContentDescription(CharSequence)
1095 * @see #setContentDescription(int)
1096 */
1097 public abstract CharSequence getContentDescription();
Adam Powell661c9082010-07-02 10:09:44 -07001098 }
Adam Powell2b6230e2010-09-07 17:55:25 -07001099
1100 /**
1101 * Callback interface invoked when a tab is focused, unfocused, added, or removed.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001102 *
1103 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1104 * toolbar action bars. Consider using other
1105 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1106 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -07001107 */
1108 public interface TabListener {
1109 /**
1110 * Called when a tab enters the selected state.
1111 *
1112 * @param tab The tab that was selected
1113 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1114 * during a tab switch. The previous tab's unselect and this tab's select will be
Adam Powell0c24a552010-11-03 16:44:11 -07001115 * executed in a single transaction. This FragmentTransaction does not support
1116 * being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001117 */
1118 public void onTabSelected(Tab tab, FragmentTransaction ft);
1119
1120 /**
1121 * Called when a tab exits the selected state.
1122 *
1123 * @param tab The tab that was unselected
1124 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1125 * during a tab switch. This tab's unselect and the newly selected tab's select
Adam Powell0c24a552010-11-03 16:44:11 -07001126 * will be executed in a single transaction. This FragmentTransaction does not
1127 * support being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001128 */
1129 public void onTabUnselected(Tab tab, FragmentTransaction ft);
Adam Powell7f9b9052010-10-19 16:56:07 -07001130
1131 /**
1132 * Called when a tab that is already selected is chosen again by the user.
1133 * Some applications may use this action to return to the top level of a category.
1134 *
1135 * @param tab The tab that was reselected.
1136 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
Adam Powell0c24a552010-11-03 16:44:11 -07001137 * once this method returns. This FragmentTransaction does not support
1138 * being added to the back stack.
Adam Powell7f9b9052010-10-19 16:56:07 -07001139 */
1140 public void onTabReselected(Tab tab, FragmentTransaction ft);
Adam Powell2b6230e2010-09-07 17:55:25 -07001141 }
Adam Powell9ab97872010-10-26 21:47:29 -07001142
1143 /**
1144 * Per-child layout information associated with action bar custom views.
1145 *
1146 * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
1147 */
1148 public static class LayoutParams extends MarginLayoutParams {
1149 /**
1150 * Gravity for the view associated with these LayoutParams.
1151 *
1152 * @see android.view.Gravity
1153 */
1154 @ViewDebug.ExportedProperty(category = "layout", mapping = {
1155 @ViewDebug.IntToString(from = -1, to = "NONE"),
1156 @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"),
1157 @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
1158 @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
1159 @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"),
1160 @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"),
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001161 @ViewDebug.IntToString(from = Gravity.START, to = "START"),
1162 @ViewDebug.IntToString(from = Gravity.END, to = "END"),
Adam Powell9ab97872010-10-26 21:47:29 -07001163 @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"),
1164 @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"),
1165 @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
1166 @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"),
1167 @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
1168 @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
1169 })
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001170 public int gravity = Gravity.NO_GRAVITY;
Adam Powell9ab97872010-10-26 21:47:29 -07001171
Tor Norbyed9273d62013-05-30 15:59:53 -07001172 public LayoutParams(@NonNull Context c, AttributeSet attrs) {
Adam Powell9ab97872010-10-26 21:47:29 -07001173 super(c, attrs);
1174
1175 TypedArray a = c.obtainStyledAttributes(attrs,
1176 com.android.internal.R.styleable.ActionBar_LayoutParams);
1177 gravity = a.getInt(
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001178 com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity,
1179 Gravity.NO_GRAVITY);
Dianne Hackbornab0f4852011-09-12 16:59:06 -07001180 a.recycle();
Adam Powell9ab97872010-10-26 21:47:29 -07001181 }
1182
1183 public LayoutParams(int width, int height) {
1184 super(width, height);
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001185 this.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
Adam Powell9ab97872010-10-26 21:47:29 -07001186 }
1187
1188 public LayoutParams(int width, int height, int gravity) {
1189 super(width, height);
1190 this.gravity = gravity;
1191 }
1192
1193 public LayoutParams(int gravity) {
1194 this(WRAP_CONTENT, MATCH_PARENT, gravity);
1195 }
1196
1197 public LayoutParams(LayoutParams source) {
1198 super(source);
1199
1200 this.gravity = source.gravity;
1201 }
1202
1203 public LayoutParams(ViewGroup.LayoutParams source) {
1204 super(source);
1205 }
1206 }
Adam Powell33b97432010-04-20 10:01:14 -07001207}