blob: c4ddf1f8d8ac900c5d2dbf1bf6da33b98a8c86a6 [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
Adam Powell9ab97872010-10-26 21:47:29 -070019import android.content.Context;
20import android.content.res.TypedArray;
Adam Powell33b97432010-04-20 10:01:14 -070021import android.graphics.drawable.Drawable;
Adam Powell9ab97872010-10-26 21:47:29 -070022import android.util.AttributeSet;
23import android.view.Gravity;
Adam Powell33b97432010-04-20 10:01:14 -070024import android.view.View;
Adam Powell9ab97872010-10-26 21:47:29 -070025import android.view.ViewDebug;
26import android.view.ViewGroup;
27import android.view.ViewGroup.MarginLayoutParams;
Adam Powell6b336f82010-08-10 20:13:01 -070028import android.view.Window;
Adam Powella4082912010-06-04 18:34:02 -070029import android.widget.SpinnerAdapter;
Adam Powell33b97432010-04-20 10:01:14 -070030
31/**
Scott Maine797ed62011-09-22 16:17:45 -070032 * 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>
Scott Main36193d02011-07-12 15:24:01 -070044 * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
45 * android.app.Activity#getActionBar getActionBar()}.</p>
Scott Maine797ed62011-09-22 16:17:45 -070046 * <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
51 * {@link ActionBar}.
Joe Fernandezb54e7a32011-10-03 15:09:50 -070052 * <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>
57 * </div>
Adam Powell33b97432010-04-20 10:01:14 -070058 */
59public abstract class ActionBar {
Adam Powella1700782010-05-13 13:27:35 -070060 /**
Adam Powella4082912010-06-04 18:34:02 -070061 * Standard navigation mode. Consists of either a logo or icon
Adam Powella1700782010-05-13 13:27:35 -070062 * and title text with an optional subtitle. Clicking any of these elements
Adam Powellcf035762010-12-06 11:49:45 -080063 * will dispatch onOptionsItemSelected to the host Activity with
Adam Powella1700782010-05-13 13:27:35 -070064 * a MenuItem with item ID android.R.id.home.
65 */
Adam Powella4082912010-06-04 18:34:02 -070066 public static final int NAVIGATION_MODE_STANDARD = 0;
Adam Powell33b97432010-04-20 10:01:14 -070067
68 /**
Adam Powell9ab97872010-10-26 21:47:29 -070069 * 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.
Adam Powell33b97432010-04-20 10:01:14 -070072 */
Adam Powell9ab97872010-10-26 21:47:29 -070073 public static final int NAVIGATION_MODE_LIST = 1;
Adam Powell33b97432010-04-20 10:01:14 -070074
75 /**
76 * Tab navigation mode. Instead of static title text this mode
77 * presents a series of tabs for navigation within the activity.
78 */
79 public static final int NAVIGATION_MODE_TABS = 2;
Adam Powell33b97432010-04-20 10:01:14 -070080
81 /**
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.
Adam Powell9ab97872010-10-26 21:47:29 -070084 *
85 * @see #setDisplayOptions(int)
86 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -070087 */
88 public static final int DISPLAY_USE_LOGO = 0x1;
89
90 /**
Adam Powell9ab97872010-10-26 21:47:29 -070091 * Show 'home' elements in this action bar, leaving more space for other
Adam Powell33b97432010-04-20 10:01:14 -070092 * navigation elements. This includes logo and icon.
Adam Powell9ab97872010-10-26 21:47:29 -070093 *
94 * @see #setDisplayOptions(int)
95 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -070096 */
Adam Powell9ab97872010-10-26 21:47:29 -070097 public static final int DISPLAY_SHOW_HOME = 0x2;
98
99 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700100 * 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.
102 *
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.
105 *
Adam Powellc29f4e52011-07-13 20:40:52 -0700106 * <p>Setting this option will implicitly enable interaction with the home/up
107 * button. See {@link #setHomeButtonEnabled(boolean)}.
108 *
Adam Powell9ab97872010-10-26 21:47:29 -0700109 * @see #setDisplayOptions(int)
110 * @see #setDisplayOptions(int, int)
111 */
112 public static final int DISPLAY_HOME_AS_UP = 0x4;
113
114 /**
115 * Show the activity title and subtitle, if present.
116 *
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)
123 */
124 public static final int DISPLAY_SHOW_TITLE = 0x8;
125
126 /**
127 * Show the custom view if one has been set.
128 * @see #setCustomView(View)
129 * @see #setDisplayOptions(int)
130 * @see #setDisplayOptions(int, int)
131 */
132 public static final int DISPLAY_SHOW_CUSTOM = 0x10;
133
134 /**
Adam Powell27cba382013-01-22 18:55:20 -0800135 * Allow the title to wrap onto multiple lines if space is available
136 * @hide pending API approval
137 */
138 public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20;
139
140 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700141 * Set the action bar into custom navigation mode, supplying a view
142 * for custom navigation.
143 *
144 * Custom navigation views appear between the application icon and
145 * any action buttons and may use any space available there. Common
146 * use cases for custom navigation views might include an auto-suggesting
147 * address bar for a browser or other navigation mechanisms that do not
148 * translate well to provided navigation modes.
149 *
150 * @param view Custom navigation view to place in the ActionBar.
151 */
152 public abstract void setCustomView(View view);
Adam Powell89e06452010-06-23 20:24:52 -0700153
Adam Powell33b97432010-04-20 10:01:14 -0700154 /**
Adam Powella4082912010-06-04 18:34:02 -0700155 * Set the action bar into custom navigation mode, supplying a view
156 * for custom navigation.
Adam Powell33b97432010-04-20 10:01:14 -0700157 *
Adam Powellef704442010-11-16 14:48:22 -0800158 * <p>Custom navigation views appear between the application icon and
Adam Powell33b97432010-04-20 10:01:14 -0700159 * any action buttons and may use any space available there. Common
Adam Powella4082912010-06-04 18:34:02 -0700160 * use cases for custom navigation views might include an auto-suggesting
161 * address bar for a browser or other navigation mechanisms that do not
Adam Powellef704442010-11-16 14:48:22 -0800162 * translate well to provided navigation modes.</p>
163 *
164 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
165 * the custom view to be displayed.</p>
Adam Powell33b97432010-04-20 10:01:14 -0700166 *
167 * @param view Custom navigation view to place in the ActionBar.
Adam Powell9ab97872010-10-26 21:47:29 -0700168 * @param layoutParams How this custom view should layout in the bar.
Adam Powellef704442010-11-16 14:48:22 -0800169 *
170 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700171 */
Adam Powell9ab97872010-10-26 21:47:29 -0700172 public abstract void setCustomView(View view, LayoutParams layoutParams);
173
174 /**
Adam Powell3f476b32011-01-03 19:25:36 -0800175 * Set the action bar into custom navigation mode, supplying a view
176 * for custom navigation.
177 *
178 * <p>Custom navigation views appear between the application icon and
179 * any action buttons and may use any space available there. Common
180 * use cases for custom navigation views might include an auto-suggesting
181 * address bar for a browser or other navigation mechanisms that do not
182 * translate well to provided navigation modes.</p>
183 *
184 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
185 * the custom view to be displayed.</p>
186 *
187 * @param resId Resource ID of a layout to inflate into the ActionBar.
188 *
189 * @see #setDisplayOptions(int, int)
190 */
191 public abstract void setCustomView(int resId);
192
193 /**
Adam Powell1969b872011-03-22 11:52:48 -0700194 * Set the icon to display in the 'home' section of the action bar.
195 * The action bar will use an icon specified by its style or the
196 * activity icon by default.
197 *
198 * Whether the home section shows an icon or logo is controlled
199 * by the display option {@link #DISPLAY_USE_LOGO}.
200 *
201 * @param resId Resource ID of a drawable to show as an icon.
202 *
203 * @see #setDisplayUseLogoEnabled(boolean)
204 * @see #setDisplayShowHomeEnabled(boolean)
205 */
206 public abstract void setIcon(int resId);
207
208 /**
209 * Set the icon to display in the 'home' section of the action bar.
210 * The action bar will use an icon specified by its style or the
211 * activity icon by default.
212 *
213 * Whether the home section shows an icon or logo is controlled
214 * by the display option {@link #DISPLAY_USE_LOGO}.
215 *
216 * @param icon Drawable to show as an icon.
217 *
218 * @see #setDisplayUseLogoEnabled(boolean)
219 * @see #setDisplayShowHomeEnabled(boolean)
220 */
221 public abstract void setIcon(Drawable icon);
222
223 /**
224 * Set the logo to display in the 'home' section of the action bar.
225 * The action bar will use a logo specified by its style or the
226 * activity logo by default.
227 *
228 * Whether the home section shows an icon or logo is controlled
229 * by the display option {@link #DISPLAY_USE_LOGO}.
230 *
231 * @param resId Resource ID of a drawable to show as a logo.
232 *
233 * @see #setDisplayUseLogoEnabled(boolean)
234 * @see #setDisplayShowHomeEnabled(boolean)
235 */
236 public abstract void setLogo(int resId);
237
238 /**
239 * Set the logo to display in the 'home' section of the action bar.
240 * The action bar will use a logo specified by its style or the
241 * activity logo by default.
242 *
243 * Whether the home section shows an icon or logo is controlled
244 * by the display option {@link #DISPLAY_USE_LOGO}.
245 *
246 * @param logo Drawable to show as a logo.
247 *
248 * @see #setDisplayUseLogoEnabled(boolean)
249 * @see #setDisplayShowHomeEnabled(boolean)
250 */
251 public abstract void setLogo(Drawable logo);
252
253 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700254 * Set the adapter and navigation callback for list navigation mode.
255 *
256 * The supplied adapter will provide views for the expanded list as well as
257 * the currently selected item. (These may be displayed differently.)
258 *
Adam Powell8515ee82010-11-30 14:09:55 -0800259 * The supplied OnNavigationListener will alert the application when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700260 * changes the current list selection.
261 *
262 * @param adapter An adapter that will provide views both to display
263 * the current navigation selection and populate views
264 * within the dropdown navigation menu.
Adam Powell8515ee82010-11-30 14:09:55 -0800265 * @param callback An OnNavigationListener that will receive events when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700266 * selects a navigation item.
267 */
268 public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
Adam Powell8515ee82010-11-30 14:09:55 -0800269 OnNavigationListener callback);
Adam Powell9ab97872010-10-26 21:47:29 -0700270
271 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700272 * Set the selected navigation item in list or tabbed navigation modes.
Adam Powell17809772010-07-21 13:25:11 -0700273 *
274 * @param position Position of the item to select.
275 */
276 public abstract void setSelectedNavigationItem(int position);
277
278 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700279 * Get the position of the selected navigation item in list or tabbed navigation modes.
280 *
281 * @return Position of the selected item.
Adam Powell17809772010-07-21 13:25:11 -0700282 */
Adam Powell9ab97872010-10-26 21:47:29 -0700283 public abstract int getSelectedNavigationIndex();
284
285 /**
286 * Get the number of navigation items present in the current navigation mode.
287 *
288 * @return Number of navigation items.
289 */
290 public abstract int getNavigationItemCount();
Adam Powell17809772010-07-21 13:25:11 -0700291
292 /**
Adam Powellef704442010-11-16 14:48:22 -0800293 * Set the action bar's title. This will only be displayed if
294 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powell0e94b512010-06-29 17:58:20 -0700295 *
296 * @param title Title to set
Adam Powella66c7b02010-07-28 15:28:25 -0700297 *
298 * @see #setTitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800299 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700300 */
301 public abstract void setTitle(CharSequence title);
302
303 /**
Adam Powellef704442010-11-16 14:48:22 -0800304 * Set the action bar's title. This will only be displayed if
305 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700306 *
307 * @param resId Resource ID of title string to set
308 *
309 * @see #setTitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800310 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700311 */
312 public abstract void setTitle(int resId);
313
314 /**
Adam Powellef704442010-11-16 14:48:22 -0800315 * Set the action bar's subtitle. This will only be displayed if
316 * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
317 * subtitle entirely.
Adam Powell0e94b512010-06-29 17:58:20 -0700318 *
319 * @param subtitle Subtitle to set
Adam Powella66c7b02010-07-28 15:28:25 -0700320 *
321 * @see #setSubtitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800322 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700323 */
324 public abstract void setSubtitle(CharSequence subtitle);
325
326 /**
Adam Powellef704442010-11-16 14:48:22 -0800327 * Set the action bar's subtitle. This will only be displayed if
328 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700329 *
330 * @param resId Resource ID of subtitle string to set
331 *
332 * @see #setSubtitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800333 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700334 */
335 public abstract void setSubtitle(int resId);
336
337 /**
Adam Powella1700782010-05-13 13:27:35 -0700338 * Set display options. This changes all display option bits at once. To change
339 * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
Adam Powell33b97432010-04-20 10:01:14 -0700340 *
341 * @param options A combination of the bits defined by the DISPLAY_ constants
342 * defined in ActionBar.
343 */
344 public abstract void setDisplayOptions(int options);
345
346 /**
Adam Powella1700782010-05-13 13:27:35 -0700347 * Set selected display options. Only the options specified by mask will be changed.
348 * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
349 *
Adam Powell9ab97872010-10-26 21:47:29 -0700350 * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
351 * {@link #DISPLAY_SHOW_HOME} option.
Ben Komalo5ad7af62010-11-01 12:04:51 -0700352 * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
Adam Powell9ab97872010-10-26 21:47:29 -0700353 * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
Adam Powella1700782010-05-13 13:27:35 -0700354 *
355 * @param options A combination of the bits defined by the DISPLAY_ constants
356 * defined in ActionBar.
357 * @param mask A bit mask declaring which display options should be changed.
358 */
359 public abstract void setDisplayOptions(int options, int mask);
Adam Powell3f476b32011-01-03 19:25:36 -0800360
361 /**
362 * Set whether to display the activity logo rather than the activity icon.
363 * A logo is often a wider, more detailed image.
364 *
365 * <p>To set several display options at once, see the setDisplayOptions methods.
366 *
367 * @param useLogo true to use the activity logo, false to use the activity icon.
368 *
369 * @see #setDisplayOptions(int)
370 * @see #setDisplayOptions(int, int)
371 */
372 public abstract void setDisplayUseLogoEnabled(boolean useLogo);
373
374 /**
375 * Set whether to include the application home affordance in the action bar.
376 * Home is presented as either an activity icon or logo.
377 *
378 * <p>To set several display options at once, see the setDisplayOptions methods.
379 *
380 * @param showHome true to show home, false otherwise.
381 *
382 * @see #setDisplayOptions(int)
383 * @see #setDisplayOptions(int, int)
384 */
385 public abstract void setDisplayShowHomeEnabled(boolean showHome);
386
387 /**
388 * Set whether home should be displayed as an "up" affordance.
389 * Set this to true if selecting "home" returns up by a single level in your UI
390 * rather than back to the top level or front page.
391 *
392 * <p>To set several display options at once, see the setDisplayOptions methods.
393 *
394 * @param showHomeAsUp true to show the user that selecting home will return one
395 * level up rather than to the top level of the app.
396 *
397 * @see #setDisplayOptions(int)
398 * @see #setDisplayOptions(int, int)
399 */
400 public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
401
402 /**
403 * Set whether an activity title/subtitle should be displayed.
404 *
405 * <p>To set several display options at once, see the setDisplayOptions methods.
406 *
407 * @param showTitle true to display a title/subtitle if present.
408 *
409 * @see #setDisplayOptions(int)
410 * @see #setDisplayOptions(int, int)
411 */
412 public abstract void setDisplayShowTitleEnabled(boolean showTitle);
413
414 /**
415 * Set whether a custom view should be displayed, if set.
416 *
417 * <p>To set several display options at once, see the setDisplayOptions methods.
418 *
419 * @param showCustom true if the currently set custom view should be displayed, false otherwise.
420 *
421 * @see #setDisplayOptions(int)
422 * @see #setDisplayOptions(int, int)
423 */
424 public abstract void setDisplayShowCustomEnabled(boolean showCustom);
425
Adam Powella1700782010-05-13 13:27:35 -0700426 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700427 * Set the ActionBar's background. This will be used for the primary
428 * action bar.
Adam Powell33b97432010-04-20 10:01:14 -0700429 *
430 * @param d Background drawable
Adam Powellf88b9152011-09-07 14:54:32 -0700431 * @see #setStackedBackgroundDrawable(Drawable)
432 * @see #setSplitBackgroundDrawable(Drawable)
Adam Powell33b97432010-04-20 10:01:14 -0700433 */
434 public abstract void setBackgroundDrawable(Drawable d);
Adam Powellef704442010-11-16 14:48:22 -0800435
436 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700437 * Set the ActionBar's stacked background. This will appear
438 * in the second row/stacked bar on some devices and configurations.
439 *
440 * @param d Background drawable for the stacked row
441 */
Adam Powell01453222011-09-07 16:13:36 -0700442 public void setStackedBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700443
444 /**
445 * Set the ActionBar's split background. This will appear in
446 * the split action bar containing menu-provided action buttons
447 * on some devices and configurations.
Scott Maine797ed62011-09-22 16:17:45 -0700448 * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
Adam Powellf88b9152011-09-07 14:54:32 -0700449 *
450 * @param d Background drawable for the split bar
451 */
Adam Powell01453222011-09-07 16:13:36 -0700452 public void setSplitBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700453
454 /**
Adam Powellef704442010-11-16 14:48:22 -0800455 * @return The current custom view.
456 */
457 public abstract View getCustomView();
458
Adam Powell33b97432010-04-20 10:01:14 -0700459 /**
Adam Powella4082912010-06-04 18:34:02 -0700460 * Returns the current ActionBar title in standard mode.
461 * Returns null if {@link #getNavigationMode()} would not return
462 * {@link #NAVIGATION_MODE_STANDARD}.
463 *
464 * @return The current ActionBar title or null.
Adam Powell33b97432010-04-20 10:01:14 -0700465 */
466 public abstract CharSequence getTitle();
467
468 /**
Adam Powella4082912010-06-04 18:34:02 -0700469 * Returns the current ActionBar subtitle in standard mode.
470 * Returns null if {@link #getNavigationMode()} would not return
471 * {@link #NAVIGATION_MODE_STANDARD}.
472 *
473 * @return The current ActionBar subtitle or null.
Adam Powell33b97432010-04-20 10:01:14 -0700474 */
475 public abstract CharSequence getSubtitle();
476
477 /**
Adam Powella4082912010-06-04 18:34:02 -0700478 * Returns the current navigation mode. The result will be one of:
479 * <ul>
480 * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
Adam Powell9ab97872010-10-26 21:47:29 -0700481 * <li>{@link #NAVIGATION_MODE_LIST}</li>
Adam Powella4082912010-06-04 18:34:02 -0700482 * <li>{@link #NAVIGATION_MODE_TABS}</li>
Adam Powella4082912010-06-04 18:34:02 -0700483 * </ul>
484 *
Adam Powell33b97432010-04-20 10:01:14 -0700485 * @return The current navigation mode.
486 */
487 public abstract int getNavigationMode();
Adam Powell9ab97872010-10-26 21:47:29 -0700488
489 /**
490 * Set the current navigation mode.
491 *
492 * @param mode The new mode to set.
493 * @see #NAVIGATION_MODE_STANDARD
494 * @see #NAVIGATION_MODE_LIST
495 * @see #NAVIGATION_MODE_TABS
496 */
497 public abstract void setNavigationMode(int mode);
498
Adam Powell33b97432010-04-20 10:01:14 -0700499 /**
500 * @return The current set of display options.
501 */
502 public abstract int getDisplayOptions();
Adam Powell661c9082010-07-02 10:09:44 -0700503
504 /**
Adam Powell661c9082010-07-02 10:09:44 -0700505 * Create and return a new {@link Tab}.
506 * This tab will not be included in the action bar until it is added.
507 *
Dianne Hackborn2f048832011-06-16 13:31:57 -0700508 * <p>Very often tabs will be used to switch between {@link Fragment}
509 * objects. Here is a typical implementation of such tabs:</p>
510 *
511 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
512 * complete}
513 *
Adam Powell661c9082010-07-02 10:09:44 -0700514 * @return A new Tab
515 *
516 * @see #addTab(Tab)
Adam Powell661c9082010-07-02 10:09:44 -0700517 */
518 public abstract Tab newTab();
519
520 /**
521 * 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 -0700522 * If this is the first tab to be added it will become the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700523 *
524 * @param tab Tab to add
525 */
526 public abstract void addTab(Tab tab);
527
528 /**
Adam Powell81b89442010-11-02 17:58:56 -0700529 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
530 *
531 * @param tab Tab to add
532 * @param setSelected True if the added tab should become the selected tab.
533 */
534 public abstract void addTab(Tab tab, boolean setSelected);
535
536 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700537 * Add a tab for use in tabbed navigation mode. The tab will be inserted at
Adam Powell81b89442010-11-02 17:58:56 -0700538 * <code>position</code>. If this is the first tab to be added it will become
539 * the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700540 *
541 * @param tab The tab to add
542 * @param position The new position of the tab
543 */
Adam Powell2b6230e2010-09-07 17:55:25 -0700544 public abstract void addTab(Tab tab, int position);
Adam Powell661c9082010-07-02 10:09:44 -0700545
546 /**
Adam Powell81b89442010-11-02 17:58:56 -0700547 * Add a tab for use in tabbed navigation mode. The tab will be insterted at
548 * <code>position</code>.
549 *
550 * @param tab The tab to add
551 * @param position The new position of the tab
552 * @param setSelected True if the added tab should become the selected tab.
553 */
554 public abstract void addTab(Tab tab, int position, boolean setSelected);
555
556 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700557 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
558 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700559 *
560 * @param tab The tab to remove
561 */
562 public abstract void removeTab(Tab tab);
563
564 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700565 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
566 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700567 *
568 * @param position Position of the tab to remove
569 */
570 public abstract void removeTabAt(int position);
571
572 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700573 * Remove all tabs from the action bar and deselect the current tab.
574 */
575 public abstract void removeAllTabs();
576
577 /**
Adam Powell661c9082010-07-02 10:09:44 -0700578 * Select the specified tab. If it is not a child of this action bar it will be added.
579 *
Adam Powell9ab97872010-10-26 21:47:29 -0700580 * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
581 *
Adam Powell661c9082010-07-02 10:09:44 -0700582 * @param tab Tab to select
583 */
584 public abstract void selectTab(Tab tab);
585
586 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700587 * Returns the currently selected tab if in tabbed navigation mode and there is at least
588 * one tab present.
589 *
590 * @return The currently selected tab or null
591 */
592 public abstract Tab getSelectedTab();
593
594 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700595 * Returns the tab at the specified index.
596 *
597 * @param index Index value in the range 0-get
598 * @return
599 */
600 public abstract Tab getTabAt(int index);
601
602 /**
Adam Powell0c24a552010-11-03 16:44:11 -0700603 * Returns the number of tabs currently registered with the action bar.
604 * @return Tab count
605 */
606 public abstract int getTabCount();
607
608 /**
Adam Powell6b336f82010-08-10 20:13:01 -0700609 * Retrieve the current height of the ActionBar.
610 *
611 * @return The ActionBar's height
612 */
613 public abstract int getHeight();
614
615 /**
616 * Show the ActionBar if it is not currently showing.
617 * If the window hosting the ActionBar does not have the feature
618 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
619 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700620 *
621 * <p>If you are hiding the ActionBar through
622 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN},
623 * you should not call this function directly.
Adam Powell6b336f82010-08-10 20:13:01 -0700624 */
625 public abstract void show();
626
627 /**
Scott Maine797ed62011-09-22 16:17:45 -0700628 * Hide the ActionBar if it is currently showing.
Adam Powell6b336f82010-08-10 20:13:01 -0700629 * If the window hosting the ActionBar does not have the feature
630 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
631 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700632 *
633 * <p>Instead of calling this function directly, you can also cause an
634 * ActionBar using the overlay feature to hide through
635 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}.
636 * Hiding the ActionBar through this system UI flag allows you to more
637 * seamlessly hide it in conjunction with other screen decorations.
Adam Powell6b336f82010-08-10 20:13:01 -0700638 */
639 public abstract void hide();
640
641 /**
642 * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
643 */
644 public abstract boolean isShowing();
645
646 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800647 * Add a listener that will respond to menu visibility change events.
648 *
649 * @param listener The new listener to add
Adam Powell89e06452010-06-23 20:24:52 -0700650 */
Adam Powell8515ee82010-11-30 14:09:55 -0800651 public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
652
653 /**
654 * Remove a menu visibility listener. This listener will no longer receive menu
655 * visibility change events.
656 *
657 * @param listener A listener to remove that was previously added
658 */
659 public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
660
661 /**
Adam Powellc29f4e52011-07-13 20:40:52 -0700662 * Enable or disable the "home" button in the corner of the action bar. (Note that this
663 * is the application home/up affordance on the action bar, not the systemwide home
664 * button.)
665 *
666 * <p>This defaults to true for packages targeting &lt; API 14. For packages targeting
667 * API 14 or greater, the application should call this method to enable interaction
668 * with the home/up affordance.
669 *
670 * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
671 * the home button.
672 *
673 * @param enabled true to enable the home button, false to disable the home button.
674 */
Adam Powell88ab6972011-07-28 11:25:01 -0700675 public void setHomeButtonEnabled(boolean enabled) { }
676
677 /**
678 * Returns a {@link Context} with an appropriate theme for creating views that
679 * will appear in the action bar. If you are inflating or instantiating custom views
680 * that will appear in an action bar, you should use the Context returned by this method.
681 * (This includes adapters used for list navigation mode.)
682 * This will ensure that views contrast properly against the action bar.
683 *
684 * @return A themed Context for creating views
685 */
686 public Context getThemedContext() { return null; }
Adam Powellc29f4e52011-07-13 20:40:52 -0700687
688 /**
Adam Powell27cba382013-01-22 18:55:20 -0800689 * Returns true if the Title field has been truncated during layout for lack
690 * of available space.
691 *
692 * @return true if the Title field has been truncated
693 * @hide pending API approval
694 */
695 public boolean isTitleTruncated() { return false; }
696
697 /**
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700698 * Set an alternate drawable to display next to the icon/logo/title
699 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
700 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
701 *
702 * <p>If you pass <code>null</code> to this method, the default drawable from the theme
703 * will be used.</p>
704 *
705 * <p>If you implement alternate or intermediate behavior around Up, you should also
706 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
707 * to provide a correct description of the action for accessibility support.</p>
708 *
709 * @param indicator A drawable to use for the up indicator, or null to use the theme's default
710 *
711 * @see #setDisplayOptions(int, int)
712 * @see #setDisplayHomeAsUpEnabled(boolean)
713 * @see #setHomeActionContentDescription(int)
714 */
715 public void setHomeAsUpIndicator(Drawable indicator) { }
716
717 /**
718 * Set an alternate drawable to display next to the icon/logo/title
719 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
720 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
721 *
722 * <p>If you pass <code>0</code> to this method, the default drawable from the theme
723 * will be used.</p>
724 *
725 * <p>If you implement alternate or intermediate behavior around Up, you should also
726 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
727 * to provide a correct description of the action for accessibility support.</p>
728 *
729 * @param resId Resource ID of a drawable to use for the up indicator, or null
730 * to use the theme's default
731 *
732 * @see #setDisplayOptions(int, int)
733 * @see #setDisplayHomeAsUpEnabled(boolean)
734 * @see #setHomeActionContentDescription(int)
735 */
736 public void setHomeAsUpIndicator(int resId) { }
737
738 /**
739 * Set an alternate description for the Home/Up action, when enabled.
740 *
741 * <p>This description is commonly used for accessibility/screen readers when
742 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
743 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
744 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
745 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
746 * functionality such as a sliding drawer, you should also set this to accurately
747 * describe the action.</p>
748 *
749 * <p>Setting this to <code>null</code> will use the system default description.</p>
750 *
751 * @param description New description for the Home action when enabled
752 * @see #setHomeAsUpIndicator(int)
753 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
754 */
755 public void setHomeActionContentDescription(CharSequence description) { }
756
757 /**
758 * Set an alternate description for the Home/Up action, when enabled.
759 *
760 * <p>This description is commonly used for accessibility/screen readers when
761 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
762 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
763 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
764 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
765 * functionality such as a sliding drawer, you should also set this to accurately
766 * describe the action.</p>
767 *
768 * <p>Setting this to <code>0</code> will use the system default description.</p>
769 *
770 * @param resId Resource ID of a string to use as the new description
771 * for the Home action when enabled
772 * @see #setHomeAsUpIndicator(int)
773 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
774 */
775 public void setHomeActionContentDescription(int resId) { }
776
777 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800778 * Listener interface for ActionBar navigation events.
779 */
780 public interface OnNavigationListener {
Adam Powell33b97432010-04-20 10:01:14 -0700781 /**
Adam Powella4082912010-06-04 18:34:02 -0700782 * This method is called whenever a navigation item in your action bar
783 * is selected.
784 *
785 * @param itemPosition Position of the item clicked.
786 * @param itemId ID of the item clicked.
787 * @return True if the event was handled, false otherwise.
788 */
789 public boolean onNavigationItemSelected(int itemPosition, long itemId);
Adam Powell33b97432010-04-20 10:01:14 -0700790 }
Adam Powell661c9082010-07-02 10:09:44 -0700791
792 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800793 * Listener for receiving events when action bar menus are shown or hidden.
794 */
795 public interface OnMenuVisibilityListener {
796 /**
797 * Called when an action bar menu is shown or hidden. Applications may want to use
798 * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
799 * gameplay, or other activity within the main content area.
800 *
801 * @param isVisible True if an action bar menu is now visible, false if no action bar
802 * menus are visible.
803 */
804 public void onMenuVisibilityChanged(boolean isVisible);
805 }
806
807 /**
Adam Powell661c9082010-07-02 10:09:44 -0700808 * A tab in the action bar.
809 *
810 * <p>Tabs manage the hiding and showing of {@link Fragment}s.
811 */
812 public static abstract class Tab {
813 /**
814 * An invalid position for a tab.
815 *
816 * @see #getPosition()
817 */
818 public static final int INVALID_POSITION = -1;
819
820 /**
821 * Return the current position of this tab in the action bar.
822 *
823 * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
824 * the action bar.
825 */
826 public abstract int getPosition();
827
828 /**
829 * Return the icon associated with this tab.
830 *
831 * @return The tab's icon
832 */
833 public abstract Drawable getIcon();
834
835 /**
836 * Return the text of this tab.
837 *
838 * @return The tab's text
839 */
840 public abstract CharSequence getText();
841
842 /**
843 * Set the icon displayed on this tab.
844 *
845 * @param icon The drawable to use as an icon
Adam Powell9ab97872010-10-26 21:47:29 -0700846 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -0700847 */
Adam Powell9ab97872010-10-26 21:47:29 -0700848 public abstract Tab setIcon(Drawable icon);
Adam Powell661c9082010-07-02 10:09:44 -0700849
850 /**
Adam Powell32555f32010-11-17 13:49:22 -0800851 * Set the icon displayed on this tab.
852 *
853 * @param resId Resource ID referring to the drawable to use as an icon
854 * @return The current instance for call chaining
855 */
856 public abstract Tab setIcon(int resId);
857
858 /**
Adam Powell661c9082010-07-02 10:09:44 -0700859 * Set the text displayed on this tab. Text may be truncated if there is not
860 * room to display the entire string.
861 *
862 * @param text The text to display
Adam Powell9ab97872010-10-26 21:47:29 -0700863 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -0700864 */
Adam Powell9ab97872010-10-26 21:47:29 -0700865 public abstract Tab setText(CharSequence text);
Adam Powell661c9082010-07-02 10:09:44 -0700866
867 /**
Adam Powell32555f32010-11-17 13:49:22 -0800868 * Set the text displayed on this tab. Text may be truncated if there is not
869 * room to display the entire string.
870 *
871 * @param resId A resource ID referring to the text that should be displayed
872 * @return The current instance for call chaining
873 */
874 public abstract Tab setText(int resId);
875
876 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700877 * Set a custom view to be used for this tab. This overrides values set by
878 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
Adam Powell661c9082010-07-02 10:09:44 -0700879 *
Adam Powell2b6230e2010-09-07 17:55:25 -0700880 * @param view Custom view to be used as a tab.
Adam Powell9ab97872010-10-26 21:47:29 -0700881 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -0700882 */
Adam Powell9ab97872010-10-26 21:47:29 -0700883 public abstract Tab setCustomView(View view);
Adam Powell661c9082010-07-02 10:09:44 -0700884
885 /**
Adam Powell32555f32010-11-17 13:49:22 -0800886 * Set a custom view to be used for this tab. This overrides values set by
887 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
888 *
889 * @param layoutResId A layout resource to inflate and use as a custom tab view
890 * @return The current instance for call chaining
891 */
892 public abstract Tab setCustomView(int layoutResId);
893
894 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700895 * Retrieve a previously set custom view for this tab.
Adam Powell661c9082010-07-02 10:09:44 -0700896 *
Adam Powell2b6230e2010-09-07 17:55:25 -0700897 * @return The custom view set by {@link #setCustomView(View)}.
Adam Powell661c9082010-07-02 10:09:44 -0700898 */
Adam Powell2b6230e2010-09-07 17:55:25 -0700899 public abstract View getCustomView();
900
901 /**
902 * Give this Tab an arbitrary object to hold for later use.
903 *
904 * @param obj Object to store
Adam Powell9ab97872010-10-26 21:47:29 -0700905 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -0700906 */
Adam Powell9ab97872010-10-26 21:47:29 -0700907 public abstract Tab setTag(Object obj);
Adam Powell2b6230e2010-09-07 17:55:25 -0700908
909 /**
910 * @return This Tab's tag object.
911 */
912 public abstract Object getTag();
913
914 /**
915 * Set the {@link TabListener} that will handle switching to and from this tab.
916 * All tabs must have a TabListener set before being added to the ActionBar.
917 *
918 * @param listener Listener to handle tab selection events
Adam Powell9ab97872010-10-26 21:47:29 -0700919 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -0700920 */
Adam Powell9ab97872010-10-26 21:47:29 -0700921 public abstract Tab setTabListener(TabListener listener);
Adam Powell661c9082010-07-02 10:09:44 -0700922
923 /**
924 * Select this tab. Only valid if the tab has been added to the action bar.
925 */
926 public abstract void select();
Adam Powell94e56ef2011-09-06 21:22:22 -0700927
928 /**
929 * Set a description of this tab's content for use in accessibility support.
930 * If no content description is provided the title will be used.
931 *
932 * @param resId A resource ID referring to the description text
933 * @return The current instance for call chaining
934 * @see #setContentDescription(CharSequence)
935 * @see #getContentDescription()
936 */
937 public abstract Tab setContentDescription(int resId);
938
939 /**
940 * Set a description of this tab's content for use in accessibility support.
941 * If no content description is provided the title will be used.
942 *
943 * @param contentDesc Description of this tab's content
944 * @return The current instance for call chaining
945 * @see #setContentDescription(int)
946 * @see #getContentDescription()
947 */
948 public abstract Tab setContentDescription(CharSequence contentDesc);
949
950 /**
951 * Gets a brief description of this tab's content for use in accessibility support.
952 *
953 * @return Description of this tab's content
954 * @see #setContentDescription(CharSequence)
955 * @see #setContentDescription(int)
956 */
957 public abstract CharSequence getContentDescription();
Adam Powell661c9082010-07-02 10:09:44 -0700958 }
Adam Powell2b6230e2010-09-07 17:55:25 -0700959
960 /**
961 * Callback interface invoked when a tab is focused, unfocused, added, or removed.
962 */
963 public interface TabListener {
964 /**
965 * Called when a tab enters the selected state.
966 *
967 * @param tab The tab that was selected
968 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
969 * during a tab switch. The previous tab's unselect and this tab's select will be
Adam Powell0c24a552010-11-03 16:44:11 -0700970 * executed in a single transaction. This FragmentTransaction does not support
971 * being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -0700972 */
973 public void onTabSelected(Tab tab, FragmentTransaction ft);
974
975 /**
976 * Called when a tab exits the selected state.
977 *
978 * @param tab The tab that was unselected
979 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
980 * during a tab switch. This tab's unselect and the newly selected tab's select
Adam Powell0c24a552010-11-03 16:44:11 -0700981 * will be executed in a single transaction. This FragmentTransaction does not
982 * support being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -0700983 */
984 public void onTabUnselected(Tab tab, FragmentTransaction ft);
Adam Powell7f9b9052010-10-19 16:56:07 -0700985
986 /**
987 * Called when a tab that is already selected is chosen again by the user.
988 * Some applications may use this action to return to the top level of a category.
989 *
990 * @param tab The tab that was reselected.
991 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
Adam Powell0c24a552010-11-03 16:44:11 -0700992 * once this method returns. This FragmentTransaction does not support
993 * being added to the back stack.
Adam Powell7f9b9052010-10-19 16:56:07 -0700994 */
995 public void onTabReselected(Tab tab, FragmentTransaction ft);
Adam Powell2b6230e2010-09-07 17:55:25 -0700996 }
Adam Powell9ab97872010-10-26 21:47:29 -0700997
998 /**
999 * Per-child layout information associated with action bar custom views.
1000 *
1001 * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
1002 */
1003 public static class LayoutParams extends MarginLayoutParams {
1004 /**
1005 * Gravity for the view associated with these LayoutParams.
1006 *
1007 * @see android.view.Gravity
1008 */
1009 @ViewDebug.ExportedProperty(category = "layout", mapping = {
1010 @ViewDebug.IntToString(from = -1, to = "NONE"),
1011 @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"),
1012 @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
1013 @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
1014 @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"),
1015 @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"),
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001016 @ViewDebug.IntToString(from = Gravity.START, to = "START"),
1017 @ViewDebug.IntToString(from = Gravity.END, to = "END"),
Adam Powell9ab97872010-10-26 21:47:29 -07001018 @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"),
1019 @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"),
1020 @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
1021 @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"),
1022 @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
1023 @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
1024 })
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001025 public int gravity = Gravity.NO_GRAVITY;
Adam Powell9ab97872010-10-26 21:47:29 -07001026
1027 public LayoutParams(Context c, AttributeSet attrs) {
1028 super(c, attrs);
1029
1030 TypedArray a = c.obtainStyledAttributes(attrs,
1031 com.android.internal.R.styleable.ActionBar_LayoutParams);
1032 gravity = a.getInt(
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001033 com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity,
1034 Gravity.NO_GRAVITY);
Dianne Hackbornab0f4852011-09-12 16:59:06 -07001035 a.recycle();
Adam Powell9ab97872010-10-26 21:47:29 -07001036 }
1037
1038 public LayoutParams(int width, int height) {
1039 super(width, height);
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001040 this.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
Adam Powell9ab97872010-10-26 21:47:29 -07001041 }
1042
1043 public LayoutParams(int width, int height, int gravity) {
1044 super(width, height);
1045 this.gravity = gravity;
1046 }
1047
1048 public LayoutParams(int gravity) {
1049 this(WRAP_CONTENT, MATCH_PARENT, gravity);
1050 }
1051
1052 public LayoutParams(LayoutParams source) {
1053 super(source);
1054
1055 this.gravity = source.gravity;
1056 }
1057
1058 public LayoutParams(ViewGroup.LayoutParams source) {
1059 super(source);
1060 }
1061 }
Adam Powell33b97432010-04-20 10:01:14 -07001062}