blob: 831cac261d3459046d2d75890a68e756823ed6c1 [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 Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070020import android.annotation.IntDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070021import android.annotation.LayoutRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070022import android.annotation.NonNull;
23import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070024import android.annotation.StringRes;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010025import android.annotation.UnsupportedAppUsage;
Adam Powell9ab97872010-10-26 21:47:29 -070026import android.content.Context;
Adam Powelle43340c2014-03-17 19:10:43 -070027import android.content.res.Configuration;
Adam Powell9ab97872010-10-26 21:47:29 -070028import android.content.res.TypedArray;
Adam Powell33b97432010-04-20 10:01:14 -070029import android.graphics.drawable.Drawable;
Adam Powell9ab97872010-10-26 21:47:29 -070030import android.util.AttributeSet;
Adam Powelle43340c2014-03-17 19:10:43 -070031import android.view.ActionMode;
Adam Powell9ab97872010-10-26 21:47:29 -070032import android.view.Gravity;
Adam Powell07a74542014-05-30 15:52:44 -070033import android.view.KeyEvent;
Adam Powell33b97432010-04-20 10:01:14 -070034import android.view.View;
Adam Powell9ab97872010-10-26 21:47:29 -070035import android.view.ViewDebug;
36import android.view.ViewGroup;
Siva Velusamy94a6d152015-05-05 15:07:00 -070037import android.view.ViewHierarchyEncoder;
Adam Powell6b336f82010-08-10 20:13:01 -070038import android.view.Window;
Adam Powella4082912010-06-04 18:34:02 -070039import android.widget.SpinnerAdapter;
Vadim Tryshev1abe85c2017-01-06 19:30:00 -080040
Tor Norbyed9273d62013-05-30 15:59:53 -070041import java.lang.annotation.Retention;
42import java.lang.annotation.RetentionPolicy;
43
Adam Powell33b97432010-04-20 10:01:14 -070044/**
Adam Powelle43340c2014-03-17 19:10:43 -070045 * A primary toolbar within the activity that may display the activity title, application-level
46 * navigation affordances, and other interactive items.
47 *
Scott Maine797ed62011-09-22 16:17:45 -070048 * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
49 * activity's window when the activity uses the system's {@link
50 * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default.
51 * You may otherwise add the action bar by calling {@link
52 * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a
53 * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property.
Adam Powelle43340c2014-03-17 19:10:43 -070054 * </p>
55 *
56 * <p>Beginning with Android L (API level 21), the action bar may be represented by any
57 * Toolbar widget within the application layout. The application may signal to the Activity
58 * which Toolbar should be treated as the Activity's action bar. Activities that use this
59 * feature should use one of the supplied <code>.NoActionBar</code> themes, set the
60 * {@link android.R.styleable#Theme_windowActionBar windowActionBar} attribute to <code>false</code>
61 * or otherwise not request the window feature.</p>
62 *
63 * <p>By adjusting the window features requested by the theme and the layouts used for
64 * an Activity's content view, an app can use the standard system action bar on older platform
65 * releases and the newer inline toolbars on newer platform releases. The <code>ActionBar</code>
66 * object obtained from the Activity can be used to control either configuration transparently.</p>
67 *
68 * <p>When using the Holo themes the action bar shows the application icon on
Scott Maine797ed62011-09-22 16:17:45 -070069 * the left, followed by the activity title. If your activity has an options menu, you can make
70 * select items accessible directly from the action bar as "action items". You can also
71 * modify various characteristics of the action bar or remove it completely.</p>
Adam Powelle43340c2014-03-17 19:10:43 -070072 *
Alan Viverette830960c2014-06-06 15:48:55 -070073 * <p>When using the Material themes (default in API 21 or newer) the navigation button
Adam Powelle43340c2014-03-17 19:10:43 -070074 * (formerly "Home") takes over the space previously occupied by the application icon.
75 * Apps wishing to express a stronger branding should use their brand colors heavily
76 * in the action bar and other application chrome or use a {@link #setLogo(int) logo}
77 * in place of their standard title text.</p>
78 *
Scott Main36193d02011-07-12 15:24:01 -070079 * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
80 * android.app.Activity#getActionBar getActionBar()}.</p>
Adam Powelle43340c2014-03-17 19:10:43 -070081 *
Scott Maine797ed62011-09-22 16:17:45 -070082 * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions,
83 * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in
84 * your activity, you can enable an action mode that offers actions specific to the selected
85 * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the
86 * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for
Adam Powelle43340c2014-03-17 19:10:43 -070087 * {@link ActionBar}.</p>
88 *
Joe Fernandezb54e7a32011-10-03 15:09:50 -070089 * <div class="special reference">
90 * <h3>Developer Guides</h3>
91 * <p>For information about how to use the action bar, including how to add action items, navigation
92 * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action
93 * Bar</a> developer guide.</p>
94 * </div>
Adam Powell33b97432010-04-20 10:01:14 -070095 */
96public abstract class ActionBar {
Tor Norbyed9273d62013-05-30 15:59:53 -070097 /** @hide */
98 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -070099 @IntDef(prefix = { "NAVIGATION_MODE_" }, value = {
100 NAVIGATION_MODE_STANDARD,
101 NAVIGATION_MODE_LIST,
102 NAVIGATION_MODE_TABS
103 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700104 public @interface NavigationMode {}
105
Adam Powella1700782010-05-13 13:27:35 -0700106 /**
Adam Powella4082912010-06-04 18:34:02 -0700107 * Standard navigation mode. Consists of either a logo or icon
Adam Powella1700782010-05-13 13:27:35 -0700108 * and title text with an optional subtitle. Clicking any of these elements
Adam Powellcf035762010-12-06 11:49:45 -0800109 * will dispatch onOptionsItemSelected to the host Activity with
Adam Powella1700782010-05-13 13:27:35 -0700110 * a MenuItem with item ID android.R.id.home.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700111 *
112 * @deprecated Action bar navigation modes are deprecated and not supported by inline
113 * toolbar action bars. Consider using other
114 * <a href="http://developer.android.com/design/patterns/navigation.html">common
115 * navigation patterns</a> instead.
Adam Powella1700782010-05-13 13:27:35 -0700116 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700117 @Deprecated
Adam Powella4082912010-06-04 18:34:02 -0700118 public static final int NAVIGATION_MODE_STANDARD = 0;
Adam Powell33b97432010-04-20 10:01:14 -0700119
120 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700121 * List navigation mode. Instead of static title text this mode
122 * presents a list menu for navigation within the activity.
123 * e.g. this might be presented to the user as a dropdown list.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700124 *
125 * @deprecated Action bar navigation modes are deprecated and not supported by inline
126 * toolbar action bars. Consider using other
127 * <a href="http://developer.android.com/design/patterns/navigation.html">common
128 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700129 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700130 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700131 public static final int NAVIGATION_MODE_LIST = 1;
Adam Powell33b97432010-04-20 10:01:14 -0700132
133 /**
134 * Tab navigation mode. Instead of static title text this mode
135 * presents a series of tabs for navigation within the activity.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700136 *
137 * @deprecated Action bar navigation modes are deprecated and not supported by inline
138 * toolbar action bars. Consider using other
139 * <a href="http://developer.android.com/design/patterns/navigation.html">common
140 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700141 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700142 @Deprecated
Adam Powell33b97432010-04-20 10:01:14 -0700143 public static final int NAVIGATION_MODE_TABS = 2;
Adam Powell33b97432010-04-20 10:01:14 -0700144
Tor Norbyed9273d62013-05-30 15:59:53 -0700145 /** @hide */
146 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700147 @IntDef(flag = true, prefix = { "DISPLAY_" }, value = {
148 DISPLAY_USE_LOGO,
149 DISPLAY_SHOW_HOME,
150 DISPLAY_HOME_AS_UP,
151 DISPLAY_SHOW_TITLE,
152 DISPLAY_SHOW_CUSTOM,
153 DISPLAY_TITLE_MULTIPLE_LINES
154 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700155 public @interface DisplayOptions {}
156
Adam Powell33b97432010-04-20 10:01:14 -0700157 /**
158 * Use logo instead of icon if available. This flag will cause appropriate
159 * navigation modes to use a wider logo in place of the standard icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700160 *
161 * @see #setDisplayOptions(int)
162 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700163 */
164 public static final int DISPLAY_USE_LOGO = 0x1;
165
166 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700167 * Show 'home' elements in this action bar, leaving more space for other
Adam Powell33b97432010-04-20 10:01:14 -0700168 * navigation elements. This includes logo and icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700169 *
170 * @see #setDisplayOptions(int)
171 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700172 */
Adam Powell9ab97872010-10-26 21:47:29 -0700173 public static final int DISPLAY_SHOW_HOME = 0x2;
174
175 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700176 * Display the 'home' element such that it appears as an 'up' affordance.
177 * e.g. show an arrow to the left indicating the action that will be taken.
178 *
179 * Set this flag if selecting the 'home' button in the action bar to return
180 * up by a single level in your UI rather than back to the top level or front page.
181 *
Adam Powellc29f4e52011-07-13 20:40:52 -0700182 * <p>Setting this option will implicitly enable interaction with the home/up
183 * button. See {@link #setHomeButtonEnabled(boolean)}.
184 *
Adam Powell9ab97872010-10-26 21:47:29 -0700185 * @see #setDisplayOptions(int)
186 * @see #setDisplayOptions(int, int)
187 */
188 public static final int DISPLAY_HOME_AS_UP = 0x4;
189
190 /**
191 * Show the activity title and subtitle, if present.
192 *
193 * @see #setTitle(CharSequence)
194 * @see #setTitle(int)
195 * @see #setSubtitle(CharSequence)
196 * @see #setSubtitle(int)
197 * @see #setDisplayOptions(int)
198 * @see #setDisplayOptions(int, int)
199 */
200 public static final int DISPLAY_SHOW_TITLE = 0x8;
201
202 /**
203 * Show the custom view if one has been set.
204 * @see #setCustomView(View)
205 * @see #setDisplayOptions(int)
206 * @see #setDisplayOptions(int, int)
207 */
208 public static final int DISPLAY_SHOW_CUSTOM = 0x10;
209
210 /**
Adam Powell27cba382013-01-22 18:55:20 -0800211 * Allow the title to wrap onto multiple lines if space is available
212 * @hide pending API approval
213 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100214 @UnsupportedAppUsage
Adam Powell27cba382013-01-22 18:55:20 -0800215 public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20;
216
217 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700218 * Set the action bar into custom navigation mode, supplying a view
219 * for custom navigation.
220 *
221 * Custom navigation views appear between the application icon and
222 * any action buttons and may use any space available there. Common
223 * use cases for custom navigation views might include an auto-suggesting
224 * address bar for a browser or other navigation mechanisms that do not
225 * translate well to provided navigation modes.
226 *
227 * @param view Custom navigation view to place in the ActionBar.
228 */
229 public abstract void setCustomView(View view);
Adam Powell89e06452010-06-23 20:24:52 -0700230
Adam Powell33b97432010-04-20 10:01:14 -0700231 /**
Adam Powella4082912010-06-04 18:34:02 -0700232 * Set the action bar into custom navigation mode, supplying a view
233 * for custom navigation.
Adam Powell33b97432010-04-20 10:01:14 -0700234 *
Adam Powellef704442010-11-16 14:48:22 -0800235 * <p>Custom navigation views appear between the application icon and
Adam Powell33b97432010-04-20 10:01:14 -0700236 * any action buttons and may use any space available there. Common
Adam Powella4082912010-06-04 18:34:02 -0700237 * use cases for custom navigation views might include an auto-suggesting
238 * address bar for a browser or other navigation mechanisms that do not
Adam Powellef704442010-11-16 14:48:22 -0800239 * translate well to provided navigation modes.</p>
240 *
241 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
242 * the custom view to be displayed.</p>
Adam Powell33b97432010-04-20 10:01:14 -0700243 *
244 * @param view Custom navigation view to place in the ActionBar.
Adam Powell9ab97872010-10-26 21:47:29 -0700245 * @param layoutParams How this custom view should layout in the bar.
Adam Powellef704442010-11-16 14:48:22 -0800246 *
247 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700248 */
Adam Powell9ab97872010-10-26 21:47:29 -0700249 public abstract void setCustomView(View view, LayoutParams layoutParams);
250
251 /**
Adam Powell3f476b32011-01-03 19:25:36 -0800252 * Set the action bar into custom navigation mode, supplying a view
253 * for custom navigation.
254 *
255 * <p>Custom navigation views appear between the application icon and
256 * any action buttons and may use any space available there. Common
257 * use cases for custom navigation views might include an auto-suggesting
258 * address bar for a browser or other navigation mechanisms that do not
259 * translate well to provided navigation modes.</p>
260 *
261 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
262 * the custom view to be displayed.</p>
263 *
264 * @param resId Resource ID of a layout to inflate into the ActionBar.
265 *
266 * @see #setDisplayOptions(int, int)
267 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700268 public abstract void setCustomView(@LayoutRes int resId);
Adam Powell3f476b32011-01-03 19:25:36 -0800269
270 /**
Adam Powell1969b872011-03-22 11:52:48 -0700271 * Set the icon to display in the 'home' section of the action bar.
272 * The action bar will use an icon specified by its style or the
273 * activity icon by default.
274 *
275 * Whether the home section shows an icon or logo is controlled
276 * by the display option {@link #DISPLAY_USE_LOGO}.
277 *
278 * @param resId Resource ID of a drawable to show as an icon.
279 *
280 * @see #setDisplayUseLogoEnabled(boolean)
281 * @see #setDisplayShowHomeEnabled(boolean)
282 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700283 public abstract void setIcon(@DrawableRes int resId);
Adam Powell1969b872011-03-22 11:52:48 -0700284
285 /**
286 * Set the icon to display in the 'home' section of the action bar.
287 * The action bar will use an icon specified by its style or the
288 * activity icon by default.
289 *
290 * Whether the home section shows an icon or logo is controlled
291 * by the display option {@link #DISPLAY_USE_LOGO}.
292 *
293 * @param icon Drawable to show as an icon.
294 *
295 * @see #setDisplayUseLogoEnabled(boolean)
296 * @see #setDisplayShowHomeEnabled(boolean)
297 */
298 public abstract void setIcon(Drawable icon);
299
300 /**
301 * Set the logo to display in the 'home' section of the action bar.
302 * The action bar will use a logo specified by its style or the
303 * activity logo by default.
304 *
305 * Whether the home section shows an icon or logo is controlled
306 * by the display option {@link #DISPLAY_USE_LOGO}.
307 *
308 * @param resId Resource ID of a drawable to show as a logo.
309 *
310 * @see #setDisplayUseLogoEnabled(boolean)
311 * @see #setDisplayShowHomeEnabled(boolean)
312 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700313 public abstract void setLogo(@DrawableRes int resId);
Adam Powell1969b872011-03-22 11:52:48 -0700314
315 /**
316 * Set the logo to display in the 'home' section of the action bar.
317 * The action bar will use a logo specified by its style or the
318 * activity logo by default.
319 *
320 * Whether the home section shows an icon or logo is controlled
321 * by the display option {@link #DISPLAY_USE_LOGO}.
322 *
323 * @param logo Drawable to show as a logo.
324 *
325 * @see #setDisplayUseLogoEnabled(boolean)
326 * @see #setDisplayShowHomeEnabled(boolean)
327 */
328 public abstract void setLogo(Drawable logo);
329
330 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700331 * Set the adapter and navigation callback for list navigation mode.
332 *
333 * The supplied adapter will provide views for the expanded list as well as
334 * the currently selected item. (These may be displayed differently.)
335 *
Adam Powell8515ee82010-11-30 14:09:55 -0800336 * The supplied OnNavigationListener will alert the application when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700337 * changes the current list selection.
338 *
339 * @param adapter An adapter that will provide views both to display
340 * the current navigation selection and populate views
341 * within the dropdown navigation menu.
Adam Powell8515ee82010-11-30 14:09:55 -0800342 * @param callback An OnNavigationListener that will receive events when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700343 * selects a navigation item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700344 *
345 * @deprecated Action bar navigation modes are deprecated and not supported by inline
346 * toolbar action bars. Consider using other
347 * <a href="http://developer.android.com/design/patterns/navigation.html">common
348 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700349 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700350 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700351 public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
Adam Powell8515ee82010-11-30 14:09:55 -0800352 OnNavigationListener callback);
Adam Powell9ab97872010-10-26 21:47:29 -0700353
354 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700355 * Set the selected navigation item in list or tabbed navigation modes.
Adam Powell17809772010-07-21 13:25:11 -0700356 *
357 * @param position Position of the item to select.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700358 *
359 * @deprecated Action bar navigation modes are deprecated and not supported by inline
360 * toolbar action bars. Consider using other
361 * <a href="http://developer.android.com/design/patterns/navigation.html">common
362 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700363 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700364 @Deprecated
Adam Powell17809772010-07-21 13:25:11 -0700365 public abstract void setSelectedNavigationItem(int position);
366
367 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700368 * Get the position of the selected navigation item in list or tabbed navigation modes.
369 *
370 * @return Position of the selected item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700371 *
372 * @deprecated Action bar navigation modes are deprecated and not supported by inline
373 * toolbar action bars. Consider using other
374 * <a href="http://developer.android.com/design/patterns/navigation.html">common
375 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700376 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700377 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700378 public abstract int getSelectedNavigationIndex();
379
380 /**
381 * Get the number of navigation items present in the current navigation mode.
382 *
383 * @return Number of navigation items.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700384 *
385 * @deprecated Action bar navigation modes are deprecated and not supported by inline
386 * toolbar action bars. Consider using other
387 * <a href="http://developer.android.com/design/patterns/navigation.html">common
388 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700389 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700390 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700391 public abstract int getNavigationItemCount();
Adam Powell17809772010-07-21 13:25:11 -0700392
393 /**
Adam Powellef704442010-11-16 14:48:22 -0800394 * Set the action bar's title. This will only be displayed if
395 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powell0e94b512010-06-29 17:58:20 -0700396 *
397 * @param title Title to set
Adam Powella66c7b02010-07-28 15:28:25 -0700398 *
399 * @see #setTitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800400 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700401 */
402 public abstract void setTitle(CharSequence title);
403
404 /**
Adam Powellef704442010-11-16 14:48:22 -0800405 * Set the action bar's title. This will only be displayed if
406 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700407 *
408 * @param resId Resource ID of title string to set
409 *
410 * @see #setTitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800411 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700412 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700413 public abstract void setTitle(@StringRes int resId);
Adam Powella66c7b02010-07-28 15:28:25 -0700414
415 /**
Adam Powellef704442010-11-16 14:48:22 -0800416 * Set the action bar's subtitle. This will only be displayed if
417 * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
418 * subtitle entirely.
Adam Powell0e94b512010-06-29 17:58:20 -0700419 *
420 * @param subtitle Subtitle to set
Adam Powella66c7b02010-07-28 15:28:25 -0700421 *
422 * @see #setSubtitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800423 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700424 */
425 public abstract void setSubtitle(CharSequence subtitle);
426
427 /**
Adam Powellef704442010-11-16 14:48:22 -0800428 * Set the action bar's subtitle. This will only be displayed if
429 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700430 *
431 * @param resId Resource ID of subtitle string to set
432 *
433 * @see #setSubtitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800434 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700435 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700436 public abstract void setSubtitle(@StringRes int resId);
Adam Powella66c7b02010-07-28 15:28:25 -0700437
438 /**
Adam Powella1700782010-05-13 13:27:35 -0700439 * Set display options. This changes all display option bits at once. To change
440 * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
Adam Powell33b97432010-04-20 10:01:14 -0700441 *
442 * @param options A combination of the bits defined by the DISPLAY_ constants
443 * defined in ActionBar.
444 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700445 public abstract void setDisplayOptions(@DisplayOptions int options);
Adam Powell33b97432010-04-20 10:01:14 -0700446
447 /**
Adam Powella1700782010-05-13 13:27:35 -0700448 * Set selected display options. Only the options specified by mask will be changed.
449 * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
450 *
Adam Powell9ab97872010-10-26 21:47:29 -0700451 * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
452 * {@link #DISPLAY_SHOW_HOME} option.
Ben Komalo5ad7af62010-11-01 12:04:51 -0700453 * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
Adam Powell9ab97872010-10-26 21:47:29 -0700454 * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
Adam Powella1700782010-05-13 13:27:35 -0700455 *
456 * @param options A combination of the bits defined by the DISPLAY_ constants
457 * defined in ActionBar.
458 * @param mask A bit mask declaring which display options should be changed.
459 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700460 public abstract void setDisplayOptions(@DisplayOptions int options, @DisplayOptions int mask);
Adam Powell3f476b32011-01-03 19:25:36 -0800461
462 /**
463 * Set whether to display the activity logo rather than the activity icon.
464 * A logo is often a wider, more detailed image.
465 *
466 * <p>To set several display options at once, see the setDisplayOptions methods.
467 *
468 * @param useLogo true to use the activity logo, false to use the activity icon.
469 *
470 * @see #setDisplayOptions(int)
471 * @see #setDisplayOptions(int, int)
472 */
473 public abstract void setDisplayUseLogoEnabled(boolean useLogo);
474
475 /**
476 * Set whether to include the application home affordance in the action bar.
477 * Home is presented as either an activity icon or logo.
478 *
479 * <p>To set several display options at once, see the setDisplayOptions methods.
480 *
481 * @param showHome true to show home, false otherwise.
482 *
483 * @see #setDisplayOptions(int)
484 * @see #setDisplayOptions(int, int)
485 */
486 public abstract void setDisplayShowHomeEnabled(boolean showHome);
487
488 /**
489 * Set whether home should be displayed as an "up" affordance.
490 * Set this to true if selecting "home" returns up by a single level in your UI
491 * rather than back to the top level or front page.
492 *
493 * <p>To set several display options at once, see the setDisplayOptions methods.
494 *
495 * @param showHomeAsUp true to show the user that selecting home will return one
496 * level up rather than to the top level of the app.
497 *
498 * @see #setDisplayOptions(int)
499 * @see #setDisplayOptions(int, int)
500 */
501 public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
502
503 /**
504 * Set whether an activity title/subtitle should be displayed.
505 *
506 * <p>To set several display options at once, see the setDisplayOptions methods.
507 *
508 * @param showTitle true to display a title/subtitle if present.
509 *
510 * @see #setDisplayOptions(int)
511 * @see #setDisplayOptions(int, int)
512 */
513 public abstract void setDisplayShowTitleEnabled(boolean showTitle);
514
515 /**
516 * Set whether a custom view should be displayed, if set.
517 *
518 * <p>To set several display options at once, see the setDisplayOptions methods.
519 *
520 * @param showCustom true if the currently set custom view should be displayed, false otherwise.
521 *
522 * @see #setDisplayOptions(int)
523 * @see #setDisplayOptions(int, int)
524 */
525 public abstract void setDisplayShowCustomEnabled(boolean showCustom);
526
Adam Powella1700782010-05-13 13:27:35 -0700527 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700528 * Set the ActionBar's background. This will be used for the primary
529 * action bar.
Adam Powell33b97432010-04-20 10:01:14 -0700530 *
531 * @param d Background drawable
Adam Powellf88b9152011-09-07 14:54:32 -0700532 * @see #setStackedBackgroundDrawable(Drawable)
533 * @see #setSplitBackgroundDrawable(Drawable)
Adam Powell33b97432010-04-20 10:01:14 -0700534 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700535 public abstract void setBackgroundDrawable(@Nullable Drawable d);
Adam Powellef704442010-11-16 14:48:22 -0800536
537 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700538 * Set the ActionBar's stacked background. This will appear
539 * in the second row/stacked bar on some devices and configurations.
540 *
541 * @param d Background drawable for the stacked row
542 */
Adam Powell01453222011-09-07 16:13:36 -0700543 public void setStackedBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700544
545 /**
546 * Set the ActionBar's split background. This will appear in
547 * the split action bar containing menu-provided action buttons
548 * on some devices and configurations.
Scott Maine797ed62011-09-22 16:17:45 -0700549 * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
Adam Powellf88b9152011-09-07 14:54:32 -0700550 *
551 * @param d Background drawable for the split bar
552 */
Adam Powell01453222011-09-07 16:13:36 -0700553 public void setSplitBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700554
555 /**
Adam Powellef704442010-11-16 14:48:22 -0800556 * @return The current custom view.
557 */
558 public abstract View getCustomView();
559
Adam Powell33b97432010-04-20 10:01:14 -0700560 /**
Adam Powella4082912010-06-04 18:34:02 -0700561 * Returns the current ActionBar title in standard mode.
562 * Returns null if {@link #getNavigationMode()} would not return
563 * {@link #NAVIGATION_MODE_STANDARD}.
564 *
565 * @return The current ActionBar title or null.
Adam Powell33b97432010-04-20 10:01:14 -0700566 */
567 public abstract CharSequence getTitle();
568
569 /**
Adam Powella4082912010-06-04 18:34:02 -0700570 * Returns the current ActionBar subtitle in standard mode.
571 * Returns null if {@link #getNavigationMode()} would not return
572 * {@link #NAVIGATION_MODE_STANDARD}.
573 *
574 * @return The current ActionBar subtitle or null.
Adam Powell33b97432010-04-20 10:01:14 -0700575 */
576 public abstract CharSequence getSubtitle();
577
578 /**
Adam Powella4082912010-06-04 18:34:02 -0700579 * Returns the current navigation mode. The result will be one of:
580 * <ul>
581 * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
Adam Powell9ab97872010-10-26 21:47:29 -0700582 * <li>{@link #NAVIGATION_MODE_LIST}</li>
Adam Powella4082912010-06-04 18:34:02 -0700583 * <li>{@link #NAVIGATION_MODE_TABS}</li>
Adam Powella4082912010-06-04 18:34:02 -0700584 * </ul>
585 *
Adam Powell33b97432010-04-20 10:01:14 -0700586 * @return The current navigation mode.
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 Powell33b97432010-04-20 10:01:14 -0700592 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700593 @Deprecated
Tor Norbyed9273d62013-05-30 15:59:53 -0700594 @NavigationMode
Adam Powell33b97432010-04-20 10:01:14 -0700595 public abstract int getNavigationMode();
Adam Powell9ab97872010-10-26 21:47:29 -0700596
597 /**
598 * Set the current navigation mode.
599 *
600 * @param mode The new mode to set.
601 * @see #NAVIGATION_MODE_STANDARD
602 * @see #NAVIGATION_MODE_LIST
603 * @see #NAVIGATION_MODE_TABS
Adam Powellfc35dfd2014-03-17 17:44:59 -0700604 *
605 * @deprecated Action bar navigation modes are deprecated and not supported by inline
606 * toolbar action bars. Consider using other
607 * <a href="http://developer.android.com/design/patterns/navigation.html">common
608 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700609 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700610 @Deprecated
Tor Norbyed9273d62013-05-30 15:59:53 -0700611 public abstract void setNavigationMode(@NavigationMode int mode);
Adam Powell9ab97872010-10-26 21:47:29 -0700612
Adam Powell33b97432010-04-20 10:01:14 -0700613 /**
614 * @return The current set of display options.
615 */
616 public abstract int getDisplayOptions();
Adam Powell661c9082010-07-02 10:09:44 -0700617
618 /**
Adam Powell661c9082010-07-02 10:09:44 -0700619 * Create and return a new {@link Tab}.
620 * This tab will not be included in the action bar until it is added.
621 *
Dianne Hackborn2f048832011-06-16 13:31:57 -0700622 * <p>Very often tabs will be used to switch between {@link Fragment}
623 * objects. Here is a typical implementation of such tabs:</p>
624 *
625 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
626 * complete}
627 *
Adam Powell661c9082010-07-02 10:09:44 -0700628 * @return A new Tab
629 *
630 * @see #addTab(Tab)
Adam Powellfc35dfd2014-03-17 17:44:59 -0700631 *
632 * @deprecated Action bar navigation modes are deprecated and not supported by inline
633 * toolbar action bars. Consider using other
634 * <a href="http://developer.android.com/design/patterns/navigation.html">common
635 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700636 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700637 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700638 public abstract Tab newTab();
639
640 /**
641 * 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 -0700642 * If this is the first tab to be added it will become the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700643 *
644 * @param tab Tab to add
Adam Powellfc35dfd2014-03-17 17:44:59 -0700645 *
646 * @deprecated Action bar navigation modes are deprecated and not supported by inline
647 * toolbar action bars. Consider using other
648 * <a href="http://developer.android.com/design/patterns/navigation.html">common
649 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700650 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700651 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700652 public abstract void addTab(Tab tab);
653
654 /**
Adam Powell81b89442010-11-02 17:58:56 -0700655 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
656 *
657 * @param tab Tab to add
658 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700659 *
660 * @deprecated Action bar navigation modes are deprecated and not supported by inline
661 * toolbar action bars. Consider using other
662 * <a href="http://developer.android.com/design/patterns/navigation.html">common
663 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700664 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700665 @Deprecated
Adam Powell81b89442010-11-02 17:58:56 -0700666 public abstract void addTab(Tab tab, boolean setSelected);
667
668 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700669 * Add a tab for use in tabbed navigation mode. The tab will be inserted at
Adam Powell81b89442010-11-02 17:58:56 -0700670 * <code>position</code>. If this is the first tab to be added it will become
671 * the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700672 *
673 * @param tab The tab to add
674 * @param position The new position of the tab
Adam Powellfc35dfd2014-03-17 17:44:59 -0700675 *
676 * @deprecated Action bar navigation modes are deprecated and not supported by inline
677 * toolbar action bars. Consider using other
678 * <a href="http://developer.android.com/design/patterns/navigation.html">common
679 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700680 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700681 @Deprecated
Adam Powell2b6230e2010-09-07 17:55:25 -0700682 public abstract void addTab(Tab tab, int position);
Adam Powell661c9082010-07-02 10:09:44 -0700683
684 /**
Adam Powell81b89442010-11-02 17:58:56 -0700685 * Add a tab for use in tabbed navigation mode. The tab will be insterted at
686 * <code>position</code>.
687 *
688 * @param tab The tab to add
689 * @param position The new position of the tab
690 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700691 *
692 * @deprecated Action bar navigation modes are deprecated and not supported by inline
693 * toolbar action bars. Consider using other
694 * <a href="http://developer.android.com/design/patterns/navigation.html">common
695 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700696 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700697 @Deprecated
Adam Powell81b89442010-11-02 17:58:56 -0700698 public abstract void addTab(Tab tab, int position, boolean setSelected);
699
700 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700701 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
702 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700703 *
704 * @param tab The tab to remove
Adam Powellfc35dfd2014-03-17 17:44:59 -0700705 *
706 * @deprecated Action bar navigation modes are deprecated and not supported by inline
707 * toolbar action bars. Consider using other
708 * <a href="http://developer.android.com/design/patterns/navigation.html">common
709 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700710 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700711 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700712 public abstract void removeTab(Tab tab);
713
714 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700715 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
716 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700717 *
718 * @param position Position of the tab to remove
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 Powell661c9082010-07-02 10:09:44 -0700724 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700725 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700726 public abstract void removeTabAt(int position);
727
728 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700729 * Remove all tabs from the action bar and deselect the current tab.
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 Powell9ab97872010-10-26 21:47:29 -0700735 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700736 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700737 public abstract void removeAllTabs();
738
739 /**
Adam Powell661c9082010-07-02 10:09:44 -0700740 * Select the specified tab. If it is not a child of this action bar it will be added.
741 *
Adam Powell9ab97872010-10-26 21:47:29 -0700742 * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
743 *
Adam Powell661c9082010-07-02 10:09:44 -0700744 * @param tab Tab to select
Adam Powellfc35dfd2014-03-17 17:44:59 -0700745 *
746 * @deprecated Action bar navigation modes are deprecated and not supported by inline
747 * toolbar action bars. Consider using other
748 * <a href="http://developer.android.com/design/patterns/navigation.html">common
749 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700750 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700751 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700752 public abstract void selectTab(Tab tab);
753
754 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700755 * Returns the currently selected tab if in tabbed navigation mode and there is at least
756 * one tab present.
757 *
758 * @return The currently selected tab or null
Adam Powellfc35dfd2014-03-17 17:44:59 -0700759 *
760 * @deprecated Action bar navigation modes are deprecated and not supported by inline
761 * toolbar action bars. Consider using other
762 * <a href="http://developer.android.com/design/patterns/navigation.html">common
763 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -0700764 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700765 @Deprecated
Adam Powell2b6230e2010-09-07 17:55:25 -0700766 public abstract Tab getSelectedTab();
767
768 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700769 * Returns the tab at the specified index.
770 *
771 * @param index Index value in the range 0-get
772 * @return
Adam Powellfc35dfd2014-03-17 17:44:59 -0700773 *
774 * @deprecated Action bar navigation modes are deprecated and not supported by inline
775 * toolbar action bars. Consider using other
776 * <a href="http://developer.android.com/design/patterns/navigation.html">common
777 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700778 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700779 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700780 public abstract Tab getTabAt(int index);
781
782 /**
Adam Powell0c24a552010-11-03 16:44:11 -0700783 * Returns the number of tabs currently registered with the action bar.
784 * @return Tab count
Adam Powellfc35dfd2014-03-17 17:44:59 -0700785 *
786 * @deprecated Action bar navigation modes are deprecated and not supported by inline
787 * toolbar action bars. Consider using other
788 * <a href="http://developer.android.com/design/patterns/navigation.html">common
789 * navigation patterns</a> instead.
Adam Powell0c24a552010-11-03 16:44:11 -0700790 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700791 @Deprecated
Adam Powell0c24a552010-11-03 16:44:11 -0700792 public abstract int getTabCount();
793
794 /**
Adam Powell6b336f82010-08-10 20:13:01 -0700795 * Retrieve the current height of the ActionBar.
796 *
797 * @return The ActionBar's height
798 */
799 public abstract int getHeight();
800
801 /**
802 * Show the ActionBar if it is not currently showing.
803 * If the window hosting the ActionBar does not have the feature
804 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
805 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700806 *
807 * <p>If you are hiding the ActionBar through
808 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN},
809 * you should not call this function directly.
Adam Powell6b336f82010-08-10 20:13:01 -0700810 */
811 public abstract void show();
812
813 /**
Scott Maine797ed62011-09-22 16:17:45 -0700814 * Hide the ActionBar if it is currently showing.
Adam Powell6b336f82010-08-10 20:13:01 -0700815 * If the window hosting the ActionBar does not have the feature
816 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
817 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700818 *
819 * <p>Instead of calling this function directly, you can also cause an
820 * ActionBar using the overlay feature to hide through
821 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}.
822 * Hiding the ActionBar through this system UI flag allows you to more
823 * seamlessly hide it in conjunction with other screen decorations.
Adam Powell6b336f82010-08-10 20:13:01 -0700824 */
825 public abstract void hide();
826
827 /**
828 * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
829 */
830 public abstract boolean isShowing();
831
832 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800833 * Add a listener that will respond to menu visibility change events.
834 *
835 * @param listener The new listener to add
Adam Powell89e06452010-06-23 20:24:52 -0700836 */
Adam Powell8515ee82010-11-30 14:09:55 -0800837 public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
838
839 /**
840 * Remove a menu visibility listener. This listener will no longer receive menu
841 * visibility change events.
842 *
843 * @param listener A listener to remove that was previously added
844 */
845 public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
846
847 /**
Adam Powellc29f4e52011-07-13 20:40:52 -0700848 * Enable or disable the "home" button in the corner of the action bar. (Note that this
849 * is the application home/up affordance on the action bar, not the systemwide home
850 * button.)
851 *
852 * <p>This defaults to true for packages targeting &lt; API 14. For packages targeting
853 * API 14 or greater, the application should call this method to enable interaction
854 * with the home/up affordance.
855 *
856 * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
857 * the home button.
858 *
859 * @param enabled true to enable the home button, false to disable the home button.
860 */
Adam Powell88ab6972011-07-28 11:25:01 -0700861 public void setHomeButtonEnabled(boolean enabled) { }
862
863 /**
864 * Returns a {@link Context} with an appropriate theme for creating views that
865 * will appear in the action bar. If you are inflating or instantiating custom views
866 * that will appear in an action bar, you should use the Context returned by this method.
867 * (This includes adapters used for list navigation mode.)
868 * This will ensure that views contrast properly against the action bar.
869 *
870 * @return A themed Context for creating views
871 */
872 public Context getThemedContext() { return null; }
Adam Powellc29f4e52011-07-13 20:40:52 -0700873
874 /**
Adam Powell27cba382013-01-22 18:55:20 -0800875 * Returns true if the Title field has been truncated during layout for lack
876 * of available space.
877 *
878 * @return true if the Title field has been truncated
879 * @hide pending API approval
880 */
881 public boolean isTitleTruncated() { return false; }
882
883 /**
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700884 * Set an alternate drawable to display next to the icon/logo/title
885 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
886 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
887 *
888 * <p>If you pass <code>null</code> to this method, the default drawable from the theme
889 * will be used.</p>
890 *
891 * <p>If you implement alternate or intermediate behavior around Up, you should also
892 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
893 * to provide a correct description of the action for accessibility support.</p>
894 *
895 * @param indicator A drawable to use for the up indicator, or null to use the theme's default
896 *
897 * @see #setDisplayOptions(int, int)
898 * @see #setDisplayHomeAsUpEnabled(boolean)
899 * @see #setHomeActionContentDescription(int)
900 */
901 public void setHomeAsUpIndicator(Drawable indicator) { }
902
903 /**
904 * Set an alternate drawable to display next to the icon/logo/title
905 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
906 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
907 *
908 * <p>If you pass <code>0</code> to this method, the default drawable from the theme
909 * will be used.</p>
910 *
911 * <p>If you implement alternate or intermediate behavior around Up, you should also
912 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
913 * to provide a correct description of the action for accessibility support.</p>
914 *
915 * @param resId Resource ID of a drawable to use for the up indicator, or null
916 * to use the theme's default
917 *
918 * @see #setDisplayOptions(int, int)
919 * @see #setDisplayHomeAsUpEnabled(boolean)
920 * @see #setHomeActionContentDescription(int)
921 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700922 public void setHomeAsUpIndicator(@DrawableRes int resId) { }
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700923
924 /**
925 * Set an alternate description for the Home/Up action, when enabled.
926 *
927 * <p>This description is commonly used for accessibility/screen readers when
928 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
929 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
930 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
931 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
932 * functionality such as a sliding drawer, you should also set this to accurately
933 * describe the action.</p>
934 *
935 * <p>Setting this to <code>null</code> will use the system default description.</p>
936 *
937 * @param description New description for the Home action when enabled
938 * @see #setHomeAsUpIndicator(int)
939 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
940 */
941 public void setHomeActionContentDescription(CharSequence description) { }
942
943 /**
944 * Set an alternate description for the Home/Up action, when enabled.
945 *
946 * <p>This description is commonly used for accessibility/screen readers when
947 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
948 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
949 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
950 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
951 * functionality such as a sliding drawer, you should also set this to accurately
952 * describe the action.</p>
953 *
954 * <p>Setting this to <code>0</code> will use the system default description.</p>
955 *
956 * @param resId Resource ID of a string to use as the new description
957 * for the Home action when enabled
958 * @see #setHomeAsUpIndicator(int)
959 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
960 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700961 public void setHomeActionContentDescription(@StringRes int resId) { }
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700962
Adam Powellb36e4f92014-05-01 10:23:33 -0700963 /**
964 * Enable hiding the action bar on content scroll.
965 *
966 * <p>If enabled, the action bar will scroll out of sight along with a
967 * {@link View#setNestedScrollingEnabled(boolean) nested scrolling child} view's content.
968 * The action bar must be in {@link Window#FEATURE_ACTION_BAR_OVERLAY overlay mode}
969 * to enable hiding on content scroll.</p>
970 *
971 * <p>When partially scrolled off screen the action bar is considered
972 * {@link #hide() hidden}. A call to {@link #show() show} will cause it to return to full view.
973 * </p>
974 * @param hideOnContentScroll true to enable hiding on content scroll.
975 */
976 public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
977 if (hideOnContentScroll) {
978 throw new UnsupportedOperationException("Hide on content scroll is not supported in " +
979 "this action bar configuration.");
980 }
981 }
982
983 /**
984 * Return whether the action bar is configured to scroll out of sight along with
985 * a {@link View#setNestedScrollingEnabled(boolean) nested scrolling child}.
986 *
987 * @return true if hide-on-content-scroll is enabled
988 * @see #setHideOnContentScrollEnabled(boolean)
989 */
990 public boolean isHideOnContentScrollEnabled() {
991 return false;
992 }
993
994 /**
995 * Return the current vertical offset of the action bar.
996 *
997 * <p>The action bar's current hide offset is the distance that the action bar is currently
998 * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
999 * current measured {@link #getHeight() height} (fully invisible).</p>
1000 *
1001 * @return The action bar's offset toward its fully hidden state in pixels
1002 */
1003 public int getHideOffset() {
1004 return 0;
1005 }
1006
1007 /**
1008 * Set the current hide offset of the action bar.
1009 *
1010 * <p>The action bar's current hide offset is the distance that the action bar is currently
1011 * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
1012 * current measured {@link #getHeight() height} (fully invisible).</p>
1013 *
1014 * @param offset The action bar's offset toward its fully hidden state in pixels.
1015 */
1016 public void setHideOffset(int offset) {
1017 if (offset != 0) {
1018 throw new UnsupportedOperationException("Setting an explicit action bar hide offset " +
1019 "is not supported in this action bar configuration.");
1020 }
1021 }
1022
Adam Powell14d1fa42014-07-10 16:23:39 -07001023 /**
1024 * Set the Z-axis elevation of the action bar in pixels.
1025 *
1026 * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1027 * values are closer to the user.</p>
1028 *
1029 * @param elevation Elevation value in pixels
1030 */
1031 public void setElevation(float elevation) {
1032 if (elevation != 0) {
1033 throw new UnsupportedOperationException("Setting a non-zero elevation is " +
1034 "not supported in this action bar configuration.");
1035 }
1036 }
1037
1038 /**
1039 * Get the Z-axis elevation of the action bar in pixels.
1040 *
1041 * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1042 * values are closer to the user.</p>
1043 *
1044 * @return Elevation value in pixels
1045 */
1046 public float getElevation() {
1047 return 0;
1048 }
1049
Adam Powelle43340c2014-03-17 19:10:43 -07001050 /** @hide */
1051 public void setDefaultDisplayHomeAsUpEnabled(boolean enabled) {
1052 }
1053
1054 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001055 @UnsupportedAppUsage
Adam Powelle43340c2014-03-17 19:10:43 -07001056 public void setShowHideAnimationEnabled(boolean enabled) {
1057 }
1058
1059 /** @hide */
1060 public void onConfigurationChanged(Configuration config) {
1061 }
1062
1063 /** @hide */
1064 public void dispatchMenuVisibilityChanged(boolean visible) {
1065 }
1066
1067 /** @hide */
Adam Powelle43340c2014-03-17 19:10:43 -07001068 public ActionMode startActionMode(ActionMode.Callback callback) {
1069 return null;
1070 }
1071
Adam Powell07a74542014-05-30 15:52:44 -07001072 /** @hide */
1073 public boolean openOptionsMenu() {
1074 return false;
1075 }
1076
1077 /** @hide */
Evan Rosky41823d12017-03-21 14:42:35 -07001078 public boolean closeOptionsMenu() {
1079 return false;
1080 }
1081
1082 /** @hide */
Adam Powell07a74542014-05-30 15:52:44 -07001083 public boolean invalidateOptionsMenu() {
1084 return false;
1085 }
1086
1087 /** @hide */
1088 public boolean onMenuKeyEvent(KeyEvent event) {
1089 return false;
1090 }
1091
1092 /** @hide */
Abodunrinwa Tokia04b7ad2015-06-30 17:44:04 -07001093 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
1094 return false;
1095 }
1096
1097 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001098 @UnsupportedAppUsage
Adam Powell07a74542014-05-30 15:52:44 -07001099 public boolean collapseActionView() {
1100 return false;
1101 }
1102
Adam Powellaf2d8592014-08-26 18:06:40 -07001103 /** @hide */
1104 public void setWindowTitle(CharSequence title) {
1105 }
1106
Chris Banes21b25772016-01-04 20:41:59 +00001107 /** @hide */
1108 public void onDestroy() {
1109 }
1110
George Mount5beb26172015-12-15 13:36:01 -08001111 /**
Adam Powell8515ee82010-11-30 14:09:55 -08001112 * Listener interface for ActionBar navigation events.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001113 *
1114 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1115 * toolbar action bars. Consider using other
1116 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1117 * navigation patterns</a> instead.
Adam Powell8515ee82010-11-30 14:09:55 -08001118 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07001119 @Deprecated
Adam Powell8515ee82010-11-30 14:09:55 -08001120 public interface OnNavigationListener {
Adam Powell33b97432010-04-20 10:01:14 -07001121 /**
Adam Powella4082912010-06-04 18:34:02 -07001122 * This method is called whenever a navigation item in your action bar
1123 * is selected.
1124 *
1125 * @param itemPosition Position of the item clicked.
1126 * @param itemId ID of the item clicked.
1127 * @return True if the event was handled, false otherwise.
1128 */
1129 public boolean onNavigationItemSelected(int itemPosition, long itemId);
Adam Powell33b97432010-04-20 10:01:14 -07001130 }
Adam Powell661c9082010-07-02 10:09:44 -07001131
1132 /**
Adam Powell8515ee82010-11-30 14:09:55 -08001133 * Listener for receiving events when action bar menus are shown or hidden.
1134 */
1135 public interface OnMenuVisibilityListener {
1136 /**
1137 * Called when an action bar menu is shown or hidden. Applications may want to use
1138 * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
1139 * gameplay, or other activity within the main content area.
1140 *
1141 * @param isVisible True if an action bar menu is now visible, false if no action bar
1142 * menus are visible.
1143 */
1144 public void onMenuVisibilityChanged(boolean isVisible);
1145 }
1146
1147 /**
Adam Powell661c9082010-07-02 10:09:44 -07001148 * A tab in the action bar.
1149 *
1150 * <p>Tabs manage the hiding and showing of {@link Fragment}s.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001151 *
1152 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1153 * toolbar action bars. Consider using other
1154 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1155 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -07001156 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07001157 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -07001158 public static abstract class Tab {
1159 /**
1160 * An invalid position for a tab.
1161 *
1162 * @see #getPosition()
1163 */
1164 public static final int INVALID_POSITION = -1;
1165
1166 /**
1167 * Return the current position of this tab in the action bar.
1168 *
1169 * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
1170 * the action bar.
1171 */
1172 public abstract int getPosition();
1173
1174 /**
1175 * Return the icon associated with this tab.
1176 *
1177 * @return The tab's icon
1178 */
1179 public abstract Drawable getIcon();
1180
1181 /**
1182 * Return the text of this tab.
1183 *
1184 * @return The tab's text
1185 */
1186 public abstract CharSequence getText();
1187
1188 /**
1189 * Set the icon displayed on this tab.
1190 *
1191 * @param icon The drawable to use as an icon
Adam Powell9ab97872010-10-26 21:47:29 -07001192 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001193 */
Adam Powell9ab97872010-10-26 21:47:29 -07001194 public abstract Tab setIcon(Drawable icon);
Adam Powell661c9082010-07-02 10:09:44 -07001195
1196 /**
Adam Powell32555f32010-11-17 13:49:22 -08001197 * Set the icon displayed on this tab.
1198 *
1199 * @param resId Resource ID referring to the drawable to use as an icon
1200 * @return The current instance for call chaining
1201 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001202 public abstract Tab setIcon(@DrawableRes int resId);
Adam Powell32555f32010-11-17 13:49:22 -08001203
1204 /**
Adam Powell661c9082010-07-02 10:09:44 -07001205 * Set the text displayed on this tab. Text may be truncated if there is not
1206 * room to display the entire string.
1207 *
1208 * @param text The text to display
Adam Powell9ab97872010-10-26 21:47:29 -07001209 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001210 */
Adam Powell9ab97872010-10-26 21:47:29 -07001211 public abstract Tab setText(CharSequence text);
Adam Powell661c9082010-07-02 10:09:44 -07001212
1213 /**
Adam Powell32555f32010-11-17 13:49:22 -08001214 * Set the text displayed on this tab. Text may be truncated if there is not
1215 * room to display the entire string.
1216 *
1217 * @param resId A resource ID referring to the text that should be displayed
1218 * @return The current instance for call chaining
1219 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001220 public abstract Tab setText(@StringRes int resId);
Adam Powell32555f32010-11-17 13:49:22 -08001221
1222 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001223 * Set a custom view to be used for this tab. This overrides values set by
1224 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
Adam Powell661c9082010-07-02 10:09:44 -07001225 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001226 * @param view Custom view to be used as a tab.
Adam Powell9ab97872010-10-26 21:47:29 -07001227 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001228 */
Adam Powell9ab97872010-10-26 21:47:29 -07001229 public abstract Tab setCustomView(View view);
Adam Powell661c9082010-07-02 10:09:44 -07001230
1231 /**
Adam Powell32555f32010-11-17 13:49:22 -08001232 * Set a custom view to be used for this tab. This overrides values set by
1233 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
1234 *
1235 * @param layoutResId A layout resource to inflate and use as a custom tab view
1236 * @return The current instance for call chaining
1237 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001238 public abstract Tab setCustomView(@LayoutRes int layoutResId);
Adam Powell32555f32010-11-17 13:49:22 -08001239
1240 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001241 * Retrieve a previously set custom view for this tab.
Adam Powell661c9082010-07-02 10:09:44 -07001242 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001243 * @return The custom view set by {@link #setCustomView(View)}.
Adam Powell661c9082010-07-02 10:09:44 -07001244 */
Adam Powell2b6230e2010-09-07 17:55:25 -07001245 public abstract View getCustomView();
1246
1247 /**
1248 * Give this Tab an arbitrary object to hold for later use.
1249 *
1250 * @param obj Object to store
Adam Powell9ab97872010-10-26 21:47:29 -07001251 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001252 */
Adam Powell9ab97872010-10-26 21:47:29 -07001253 public abstract Tab setTag(Object obj);
Adam Powell2b6230e2010-09-07 17:55:25 -07001254
1255 /**
1256 * @return This Tab's tag object.
1257 */
1258 public abstract Object getTag();
1259
1260 /**
1261 * Set the {@link TabListener} that will handle switching to and from this tab.
1262 * All tabs must have a TabListener set before being added to the ActionBar.
1263 *
1264 * @param listener Listener to handle tab selection events
Adam Powell9ab97872010-10-26 21:47:29 -07001265 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001266 */
Adam Powell9ab97872010-10-26 21:47:29 -07001267 public abstract Tab setTabListener(TabListener listener);
Adam Powell661c9082010-07-02 10:09:44 -07001268
1269 /**
1270 * Select this tab. Only valid if the tab has been added to the action bar.
1271 */
1272 public abstract void select();
Adam Powell94e56ef2011-09-06 21:22:22 -07001273
1274 /**
1275 * Set a description of this tab's content for use in accessibility support.
1276 * If no content description is provided the title will be used.
1277 *
1278 * @param resId A resource ID referring to the description text
1279 * @return The current instance for call chaining
1280 * @see #setContentDescription(CharSequence)
1281 * @see #getContentDescription()
1282 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001283 public abstract Tab setContentDescription(@StringRes int resId);
Adam Powell94e56ef2011-09-06 21:22:22 -07001284
1285 /**
1286 * Set a description of this tab's content for use in accessibility support.
1287 * If no content description is provided the title will be used.
1288 *
1289 * @param contentDesc Description of this tab's content
1290 * @return The current instance for call chaining
1291 * @see #setContentDescription(int)
1292 * @see #getContentDescription()
1293 */
1294 public abstract Tab setContentDescription(CharSequence contentDesc);
1295
1296 /**
1297 * Gets a brief description of this tab's content for use in accessibility support.
1298 *
1299 * @return Description of this tab's content
1300 * @see #setContentDescription(CharSequence)
1301 * @see #setContentDescription(int)
1302 */
1303 public abstract CharSequence getContentDescription();
Adam Powell661c9082010-07-02 10:09:44 -07001304 }
Adam Powell2b6230e2010-09-07 17:55:25 -07001305
1306 /**
1307 * Callback interface invoked when a tab is focused, unfocused, added, or removed.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001308 *
1309 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1310 * toolbar action bars. Consider using other
1311 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1312 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -07001313 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07001314 @Deprecated
Adam Powell2b6230e2010-09-07 17:55:25 -07001315 public interface TabListener {
1316 /**
1317 * Called when a tab enters the selected state.
1318 *
1319 * @param tab The tab that was selected
1320 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1321 * during a tab switch. The previous tab's unselect and this tab's select will be
Adam Powell0c24a552010-11-03 16:44:11 -07001322 * executed in a single transaction. This FragmentTransaction does not support
1323 * being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001324 */
1325 public void onTabSelected(Tab tab, FragmentTransaction ft);
1326
1327 /**
1328 * Called when a tab exits the selected state.
1329 *
1330 * @param tab The tab that was unselected
1331 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1332 * during a tab switch. This tab's unselect and the newly selected tab's select
Adam Powell0c24a552010-11-03 16:44:11 -07001333 * will be executed in a single transaction. This FragmentTransaction does not
1334 * support being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001335 */
1336 public void onTabUnselected(Tab tab, FragmentTransaction ft);
Adam Powell7f9b9052010-10-19 16:56:07 -07001337
1338 /**
1339 * Called when a tab that is already selected is chosen again by the user.
1340 * Some applications may use this action to return to the top level of a category.
1341 *
1342 * @param tab The tab that was reselected.
1343 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
Adam Powell0c24a552010-11-03 16:44:11 -07001344 * once this method returns. This FragmentTransaction does not support
1345 * being added to the back stack.
Adam Powell7f9b9052010-10-19 16:56:07 -07001346 */
1347 public void onTabReselected(Tab tab, FragmentTransaction ft);
Adam Powell2b6230e2010-09-07 17:55:25 -07001348 }
Adam Powell9ab97872010-10-26 21:47:29 -07001349
1350 /**
1351 * Per-child layout information associated with action bar custom views.
1352 *
1353 * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
1354 */
Adam Powelle43340c2014-03-17 19:10:43 -07001355 public static class LayoutParams extends ViewGroup.MarginLayoutParams {
Adam Powell9ab97872010-10-26 21:47:29 -07001356 /**
1357 * Gravity for the view associated with these LayoutParams.
1358 *
1359 * @see android.view.Gravity
1360 */
1361 @ViewDebug.ExportedProperty(category = "layout", mapping = {
Adam Powelle43340c2014-03-17 19:10:43 -07001362 @ViewDebug.IntToString(from = -1, to = "NONE"),
1363 @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"),
1364 @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
1365 @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
1366 @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"),
1367 @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"),
1368 @ViewDebug.IntToString(from = Gravity.START, to = "START"),
1369 @ViewDebug.IntToString(from = Gravity.END, to = "END"),
1370 @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"),
1371 @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"),
1372 @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
1373 @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"),
1374 @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
1375 @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
Adam Powell9ab97872010-10-26 21:47:29 -07001376 })
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001377 public int gravity = Gravity.NO_GRAVITY;
Adam Powell9ab97872010-10-26 21:47:29 -07001378
Tor Norbyed9273d62013-05-30 15:59:53 -07001379 public LayoutParams(@NonNull Context c, AttributeSet attrs) {
Adam Powell9ab97872010-10-26 21:47:29 -07001380 super(c, attrs);
Adam Powellb226bea2014-04-04 12:23:42 -07001381
1382 TypedArray a = c.obtainStyledAttributes(attrs,
1383 com.android.internal.R.styleable.ActionBar_LayoutParams);
1384 gravity = a.getInt(
1385 com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity,
1386 Gravity.NO_GRAVITY);
1387 a.recycle();
Adam Powell9ab97872010-10-26 21:47:29 -07001388 }
1389
1390 public LayoutParams(int width, int height) {
1391 super(width, height);
Adam Powelle021e6e2014-05-23 17:27:24 -07001392 this.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
Adam Powell9ab97872010-10-26 21:47:29 -07001393 }
1394
1395 public LayoutParams(int width, int height, int gravity) {
1396 super(width, height);
Alan Viveretteda4bd6f2014-04-14 12:58:34 -07001397
1398 this.gravity = gravity;
Adam Powell9ab97872010-10-26 21:47:29 -07001399 }
1400
1401 public LayoutParams(int gravity) {
1402 this(WRAP_CONTENT, MATCH_PARENT, gravity);
1403 }
1404
1405 public LayoutParams(LayoutParams source) {
1406 super(source);
Adam Powelle021e6e2014-05-23 17:27:24 -07001407 this.gravity = source.gravity;
Adam Powell9ab97872010-10-26 21:47:29 -07001408 }
1409
1410 public LayoutParams(ViewGroup.LayoutParams source) {
1411 super(source);
1412 }
Adam Powelle43340c2014-03-17 19:10:43 -07001413
Adam Powelld7600832014-07-01 15:22:50 -07001414 /*
1415 * Note for framework developers:
1416 *
1417 * You might notice that ActionBar.LayoutParams is missing a constructor overload
1418 * for MarginLayoutParams. While it may seem like a good idea to add one, at this
1419 * point it's dangerous for source compatibility. Upon building against a new
1420 * version of the SDK an app can end up statically linking to the new MarginLayoutParams
1421 * overload, causing a crash when running on older platform versions with no other changes.
1422 */
Siva Velusamy94a6d152015-05-05 15:07:00 -07001423
1424 /** @hide */
1425 @Override
1426 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
1427 super.encodeProperties(encoder);
1428
1429 encoder.addProperty("gravity", gravity);
1430 }
Adam Powell9ab97872010-10-26 21:47:29 -07001431 }
Adam Powell33b97432010-04-20 10:01:14 -07001432}