blob: e57327991a82dca022ce487228fc4db09fe5b9c6 [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;
Ashley Rosede3b4a72019-03-04 16:44:07 -050039import android.view.inspector.InspectableProperty;
Adam Powella4082912010-06-04 18:34:02 -070040import android.widget.SpinnerAdapter;
Vadim Tryshev1abe85c2017-01-06 19:30:00 -080041
Tor Norbyed9273d62013-05-30 15:59:53 -070042import java.lang.annotation.Retention;
43import java.lang.annotation.RetentionPolicy;
44
Adam Powell33b97432010-04-20 10:01:14 -070045/**
Adam Powelle43340c2014-03-17 19:10:43 -070046 * A primary toolbar within the activity that may display the activity title, application-level
47 * navigation affordances, and other interactive items.
48 *
Scott Maine797ed62011-09-22 16:17:45 -070049 * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
50 * activity's window when the activity uses the system's {@link
51 * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default.
52 * You may otherwise add the action bar by calling {@link
53 * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a
54 * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property.
Adam Powelle43340c2014-03-17 19:10:43 -070055 * </p>
56 *
57 * <p>Beginning with Android L (API level 21), the action bar may be represented by any
58 * Toolbar widget within the application layout. The application may signal to the Activity
59 * which Toolbar should be treated as the Activity's action bar. Activities that use this
60 * feature should use one of the supplied <code>.NoActionBar</code> themes, set the
61 * {@link android.R.styleable#Theme_windowActionBar windowActionBar} attribute to <code>false</code>
62 * or otherwise not request the window feature.</p>
63 *
64 * <p>By adjusting the window features requested by the theme and the layouts used for
65 * an Activity's content view, an app can use the standard system action bar on older platform
66 * releases and the newer inline toolbars on newer platform releases. The <code>ActionBar</code>
67 * object obtained from the Activity can be used to control either configuration transparently.</p>
68 *
69 * <p>When using the Holo themes the action bar shows the application icon on
Scott Maine797ed62011-09-22 16:17:45 -070070 * the left, followed by the activity title. If your activity has an options menu, you can make
71 * select items accessible directly from the action bar as "action items". You can also
72 * modify various characteristics of the action bar or remove it completely.</p>
Adam Powelle43340c2014-03-17 19:10:43 -070073 *
Alan Viverette830960c2014-06-06 15:48:55 -070074 * <p>When using the Material themes (default in API 21 or newer) the navigation button
Adam Powelle43340c2014-03-17 19:10:43 -070075 * (formerly "Home") takes over the space previously occupied by the application icon.
76 * Apps wishing to express a stronger branding should use their brand colors heavily
77 * in the action bar and other application chrome or use a {@link #setLogo(int) logo}
78 * in place of their standard title text.</p>
79 *
Scott Main36193d02011-07-12 15:24:01 -070080 * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
81 * android.app.Activity#getActionBar getActionBar()}.</p>
Adam Powelle43340c2014-03-17 19:10:43 -070082 *
Scott Maine797ed62011-09-22 16:17:45 -070083 * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions,
84 * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in
85 * your activity, you can enable an action mode that offers actions specific to the selected
86 * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the
87 * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for
Adam Powelle43340c2014-03-17 19:10:43 -070088 * {@link ActionBar}.</p>
89 *
Joe Fernandezb54e7a32011-10-03 15:09:50 -070090 * <div class="special reference">
91 * <h3>Developer Guides</h3>
92 * <p>For information about how to use the action bar, including how to add action items, navigation
93 * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action
94 * Bar</a> developer guide.</p>
95 * </div>
Adam Powell33b97432010-04-20 10:01:14 -070096 */
97public abstract class ActionBar {
Tor Norbyed9273d62013-05-30 15:59:53 -070098 /** @hide */
99 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700100 @IntDef(prefix = { "NAVIGATION_MODE_" }, value = {
101 NAVIGATION_MODE_STANDARD,
102 NAVIGATION_MODE_LIST,
103 NAVIGATION_MODE_TABS
104 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700105 public @interface NavigationMode {}
106
Adam Powella1700782010-05-13 13:27:35 -0700107 /**
Adam Powella4082912010-06-04 18:34:02 -0700108 * Standard navigation mode. Consists of either a logo or icon
Adam Powella1700782010-05-13 13:27:35 -0700109 * and title text with an optional subtitle. Clicking any of these elements
Adam Powellcf035762010-12-06 11:49:45 -0800110 * will dispatch onOptionsItemSelected to the host Activity with
Adam Powella1700782010-05-13 13:27:35 -0700111 * a MenuItem with item ID android.R.id.home.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700112 *
113 * @deprecated Action bar navigation modes are deprecated and not supported by inline
114 * toolbar action bars. Consider using other
115 * <a href="http://developer.android.com/design/patterns/navigation.html">common
116 * navigation patterns</a> instead.
Adam Powella1700782010-05-13 13:27:35 -0700117 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700118 @Deprecated
Adam Powella4082912010-06-04 18:34:02 -0700119 public static final int NAVIGATION_MODE_STANDARD = 0;
Adam Powell33b97432010-04-20 10:01:14 -0700120
121 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700122 * List navigation mode. Instead of static title text this mode
123 * presents a list menu for navigation within the activity.
124 * e.g. this might be presented to the user as a dropdown list.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700125 *
126 * @deprecated Action bar navigation modes are deprecated and not supported by inline
127 * toolbar action bars. Consider using other
128 * <a href="http://developer.android.com/design/patterns/navigation.html">common
129 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700130 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700131 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700132 public static final int NAVIGATION_MODE_LIST = 1;
Adam Powell33b97432010-04-20 10:01:14 -0700133
134 /**
135 * Tab navigation mode. Instead of static title text this mode
136 * presents a series of tabs for navigation within the activity.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700137 *
138 * @deprecated Action bar navigation modes are deprecated and not supported by inline
139 * toolbar action bars. Consider using other
140 * <a href="http://developer.android.com/design/patterns/navigation.html">common
141 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700142 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700143 @Deprecated
Adam Powell33b97432010-04-20 10:01:14 -0700144 public static final int NAVIGATION_MODE_TABS = 2;
Adam Powell33b97432010-04-20 10:01:14 -0700145
Tor Norbyed9273d62013-05-30 15:59:53 -0700146 /** @hide */
147 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700148 @IntDef(flag = true, prefix = { "DISPLAY_" }, value = {
149 DISPLAY_USE_LOGO,
150 DISPLAY_SHOW_HOME,
151 DISPLAY_HOME_AS_UP,
152 DISPLAY_SHOW_TITLE,
153 DISPLAY_SHOW_CUSTOM,
154 DISPLAY_TITLE_MULTIPLE_LINES
155 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700156 public @interface DisplayOptions {}
157
Adam Powell33b97432010-04-20 10:01:14 -0700158 /**
159 * Use logo instead of icon if available. This flag will cause appropriate
160 * navigation modes to use a wider logo in place of the standard icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700161 *
162 * @see #setDisplayOptions(int)
163 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700164 */
165 public static final int DISPLAY_USE_LOGO = 0x1;
166
167 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700168 * Show 'home' elements in this action bar, leaving more space for other
Adam Powell33b97432010-04-20 10:01:14 -0700169 * navigation elements. This includes logo and icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700170 *
171 * @see #setDisplayOptions(int)
172 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700173 */
Adam Powell9ab97872010-10-26 21:47:29 -0700174 public static final int DISPLAY_SHOW_HOME = 0x2;
175
176 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700177 * Display the 'home' element such that it appears as an 'up' affordance.
178 * e.g. show an arrow to the left indicating the action that will be taken.
179 *
180 * Set this flag if selecting the 'home' button in the action bar to return
181 * up by a single level in your UI rather than back to the top level or front page.
182 *
Adam Powellc29f4e52011-07-13 20:40:52 -0700183 * <p>Setting this option will implicitly enable interaction with the home/up
184 * button. See {@link #setHomeButtonEnabled(boolean)}.
185 *
Adam Powell9ab97872010-10-26 21:47:29 -0700186 * @see #setDisplayOptions(int)
187 * @see #setDisplayOptions(int, int)
188 */
189 public static final int DISPLAY_HOME_AS_UP = 0x4;
190
191 /**
192 * Show the activity title and subtitle, if present.
193 *
194 * @see #setTitle(CharSequence)
195 * @see #setTitle(int)
196 * @see #setSubtitle(CharSequence)
197 * @see #setSubtitle(int)
198 * @see #setDisplayOptions(int)
199 * @see #setDisplayOptions(int, int)
200 */
201 public static final int DISPLAY_SHOW_TITLE = 0x8;
202
203 /**
204 * Show the custom view if one has been set.
205 * @see #setCustomView(View)
206 * @see #setDisplayOptions(int)
207 * @see #setDisplayOptions(int, int)
208 */
209 public static final int DISPLAY_SHOW_CUSTOM = 0x10;
210
211 /**
Adam Powell27cba382013-01-22 18:55:20 -0800212 * Allow the title to wrap onto multiple lines if space is available
213 * @hide pending API approval
214 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100215 @UnsupportedAppUsage
Adam Powell27cba382013-01-22 18:55:20 -0800216 public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20;
217
218 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700219 * Set the action bar into custom navigation mode, supplying a view
220 * for custom navigation.
221 *
222 * Custom navigation views appear between the application icon and
223 * any action buttons and may use any space available there. Common
224 * use cases for custom navigation views might include an auto-suggesting
225 * address bar for a browser or other navigation mechanisms that do not
226 * translate well to provided navigation modes.
227 *
228 * @param view Custom navigation view to place in the ActionBar.
229 */
230 public abstract void setCustomView(View view);
Adam Powell89e06452010-06-23 20:24:52 -0700231
Adam Powell33b97432010-04-20 10:01:14 -0700232 /**
Adam Powella4082912010-06-04 18:34:02 -0700233 * Set the action bar into custom navigation mode, supplying a view
234 * for custom navigation.
Adam Powell33b97432010-04-20 10:01:14 -0700235 *
Adam Powellef704442010-11-16 14:48:22 -0800236 * <p>Custom navigation views appear between the application icon and
Adam Powell33b97432010-04-20 10:01:14 -0700237 * any action buttons and may use any space available there. Common
Adam Powella4082912010-06-04 18:34:02 -0700238 * use cases for custom navigation views might include an auto-suggesting
239 * address bar for a browser or other navigation mechanisms that do not
Adam Powellef704442010-11-16 14:48:22 -0800240 * translate well to provided navigation modes.</p>
241 *
242 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
243 * the custom view to be displayed.</p>
Adam Powell33b97432010-04-20 10:01:14 -0700244 *
245 * @param view Custom navigation view to place in the ActionBar.
Adam Powell9ab97872010-10-26 21:47:29 -0700246 * @param layoutParams How this custom view should layout in the bar.
Adam Powellef704442010-11-16 14:48:22 -0800247 *
248 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700249 */
Adam Powell9ab97872010-10-26 21:47:29 -0700250 public abstract void setCustomView(View view, LayoutParams layoutParams);
251
252 /**
Adam Powell3f476b32011-01-03 19:25:36 -0800253 * Set the action bar into custom navigation mode, supplying a view
254 * for custom navigation.
255 *
256 * <p>Custom navigation views appear between the application icon and
257 * any action buttons and may use any space available there. Common
258 * use cases for custom navigation views might include an auto-suggesting
259 * address bar for a browser or other navigation mechanisms that do not
260 * translate well to provided navigation modes.</p>
261 *
262 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
263 * the custom view to be displayed.</p>
264 *
265 * @param resId Resource ID of a layout to inflate into the ActionBar.
266 *
267 * @see #setDisplayOptions(int, int)
268 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700269 public abstract void setCustomView(@LayoutRes int resId);
Adam Powell3f476b32011-01-03 19:25:36 -0800270
271 /**
Adam Powell1969b872011-03-22 11:52:48 -0700272 * Set the icon to display in the 'home' section of the action bar.
273 * The action bar will use an icon specified by its style or the
274 * activity icon by default.
275 *
276 * Whether the home section shows an icon or logo is controlled
277 * by the display option {@link #DISPLAY_USE_LOGO}.
278 *
279 * @param resId Resource ID of a drawable to show as an icon.
280 *
281 * @see #setDisplayUseLogoEnabled(boolean)
282 * @see #setDisplayShowHomeEnabled(boolean)
283 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700284 public abstract void setIcon(@DrawableRes int resId);
Adam Powell1969b872011-03-22 11:52:48 -0700285
286 /**
287 * Set the icon to display in the 'home' section of the action bar.
288 * The action bar will use an icon specified by its style or the
289 * activity icon by default.
290 *
291 * Whether the home section shows an icon or logo is controlled
292 * by the display option {@link #DISPLAY_USE_LOGO}.
293 *
294 * @param icon Drawable to show as an icon.
295 *
296 * @see #setDisplayUseLogoEnabled(boolean)
297 * @see #setDisplayShowHomeEnabled(boolean)
298 */
299 public abstract void setIcon(Drawable icon);
300
301 /**
302 * Set the logo to display in the 'home' section of the action bar.
303 * The action bar will use a logo specified by its style or the
304 * activity logo by default.
305 *
306 * Whether the home section shows an icon or logo is controlled
307 * by the display option {@link #DISPLAY_USE_LOGO}.
308 *
309 * @param resId Resource ID of a drawable to show as a logo.
310 *
311 * @see #setDisplayUseLogoEnabled(boolean)
312 * @see #setDisplayShowHomeEnabled(boolean)
313 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700314 public abstract void setLogo(@DrawableRes int resId);
Adam Powell1969b872011-03-22 11:52:48 -0700315
316 /**
317 * Set the logo to display in the 'home' section of the action bar.
318 * The action bar will use a logo specified by its style or the
319 * activity logo by default.
320 *
321 * Whether the home section shows an icon or logo is controlled
322 * by the display option {@link #DISPLAY_USE_LOGO}.
323 *
324 * @param logo Drawable to show as a logo.
325 *
326 * @see #setDisplayUseLogoEnabled(boolean)
327 * @see #setDisplayShowHomeEnabled(boolean)
328 */
329 public abstract void setLogo(Drawable logo);
330
331 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700332 * Set the adapter and navigation callback for list navigation mode.
333 *
334 * The supplied adapter will provide views for the expanded list as well as
335 * the currently selected item. (These may be displayed differently.)
336 *
Adam Powell8515ee82010-11-30 14:09:55 -0800337 * The supplied OnNavigationListener will alert the application when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700338 * changes the current list selection.
339 *
340 * @param adapter An adapter that will provide views both to display
341 * the current navigation selection and populate views
342 * within the dropdown navigation menu.
Adam Powell8515ee82010-11-30 14:09:55 -0800343 * @param callback An OnNavigationListener that will receive events when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700344 * selects a navigation item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700345 *
346 * @deprecated Action bar navigation modes are deprecated and not supported by inline
347 * toolbar action bars. Consider using other
348 * <a href="http://developer.android.com/design/patterns/navigation.html">common
349 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700350 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700351 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700352 public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
Adam Powell8515ee82010-11-30 14:09:55 -0800353 OnNavigationListener callback);
Adam Powell9ab97872010-10-26 21:47:29 -0700354
355 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700356 * Set the selected navigation item in list or tabbed navigation modes.
Adam Powell17809772010-07-21 13:25:11 -0700357 *
358 * @param position Position of the item to select.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700359 *
360 * @deprecated Action bar navigation modes are deprecated and not supported by inline
361 * toolbar action bars. Consider using other
362 * <a href="http://developer.android.com/design/patterns/navigation.html">common
363 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700364 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700365 @Deprecated
Adam Powell17809772010-07-21 13:25:11 -0700366 public abstract void setSelectedNavigationItem(int position);
367
368 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700369 * Get the position of the selected navigation item in list or tabbed navigation modes.
370 *
371 * @return Position of the selected item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700372 *
373 * @deprecated Action bar navigation modes are deprecated and not supported by inline
374 * toolbar action bars. Consider using other
375 * <a href="http://developer.android.com/design/patterns/navigation.html">common
376 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700377 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700378 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700379 public abstract int getSelectedNavigationIndex();
380
381 /**
382 * Get the number of navigation items present in the current navigation mode.
383 *
384 * @return Number of navigation items.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700385 *
386 * @deprecated Action bar navigation modes are deprecated and not supported by inline
387 * toolbar action bars. Consider using other
388 * <a href="http://developer.android.com/design/patterns/navigation.html">common
389 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700390 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700391 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700392 public abstract int getNavigationItemCount();
Adam Powell17809772010-07-21 13:25:11 -0700393
394 /**
Adam Powellef704442010-11-16 14:48:22 -0800395 * Set the action bar's title. This will only be displayed if
396 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powell0e94b512010-06-29 17:58:20 -0700397 *
398 * @param title Title to set
Adam Powella66c7b02010-07-28 15:28:25 -0700399 *
400 * @see #setTitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800401 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700402 */
403 public abstract void setTitle(CharSequence title);
404
405 /**
Adam Powellef704442010-11-16 14:48:22 -0800406 * Set the action bar's title. This will only be displayed if
407 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700408 *
409 * @param resId Resource ID of title string to set
410 *
411 * @see #setTitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800412 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700413 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700414 public abstract void setTitle(@StringRes int resId);
Adam Powella66c7b02010-07-28 15:28:25 -0700415
416 /**
Adam Powellef704442010-11-16 14:48:22 -0800417 * Set the action bar's subtitle. This will only be displayed if
418 * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
419 * subtitle entirely.
Adam Powell0e94b512010-06-29 17:58:20 -0700420 *
421 * @param subtitle Subtitle to set
Adam Powella66c7b02010-07-28 15:28:25 -0700422 *
423 * @see #setSubtitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800424 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700425 */
426 public abstract void setSubtitle(CharSequence subtitle);
427
428 /**
Adam Powellef704442010-11-16 14:48:22 -0800429 * Set the action bar's subtitle. This will only be displayed if
430 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powella66c7b02010-07-28 15:28:25 -0700431 *
432 * @param resId Resource ID of subtitle string to set
433 *
434 * @see #setSubtitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800435 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700436 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700437 public abstract void setSubtitle(@StringRes int resId);
Adam Powella66c7b02010-07-28 15:28:25 -0700438
439 /**
Adam Powella1700782010-05-13 13:27:35 -0700440 * Set display options. This changes all display option bits at once. To change
441 * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
Adam Powell33b97432010-04-20 10:01:14 -0700442 *
443 * @param options A combination of the bits defined by the DISPLAY_ constants
444 * defined in ActionBar.
445 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700446 public abstract void setDisplayOptions(@DisplayOptions int options);
Adam Powell33b97432010-04-20 10:01:14 -0700447
448 /**
Adam Powella1700782010-05-13 13:27:35 -0700449 * Set selected display options. Only the options specified by mask will be changed.
450 * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
451 *
Adam Powell9ab97872010-10-26 21:47:29 -0700452 * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
453 * {@link #DISPLAY_SHOW_HOME} option.
Ben Komalo5ad7af62010-11-01 12:04:51 -0700454 * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
Adam Powell9ab97872010-10-26 21:47:29 -0700455 * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
Adam Powella1700782010-05-13 13:27:35 -0700456 *
457 * @param options A combination of the bits defined by the DISPLAY_ constants
458 * defined in ActionBar.
459 * @param mask A bit mask declaring which display options should be changed.
460 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700461 public abstract void setDisplayOptions(@DisplayOptions int options, @DisplayOptions int mask);
Adam Powell3f476b32011-01-03 19:25:36 -0800462
463 /**
464 * Set whether to display the activity logo rather than the activity icon.
465 * A logo is often a wider, more detailed image.
466 *
467 * <p>To set several display options at once, see the setDisplayOptions methods.
468 *
469 * @param useLogo true to use the activity logo, false to use the activity icon.
470 *
471 * @see #setDisplayOptions(int)
472 * @see #setDisplayOptions(int, int)
473 */
474 public abstract void setDisplayUseLogoEnabled(boolean useLogo);
475
476 /**
477 * Set whether to include the application home affordance in the action bar.
478 * Home is presented as either an activity icon or logo.
479 *
480 * <p>To set several display options at once, see the setDisplayOptions methods.
481 *
482 * @param showHome true to show home, false otherwise.
483 *
484 * @see #setDisplayOptions(int)
485 * @see #setDisplayOptions(int, int)
486 */
487 public abstract void setDisplayShowHomeEnabled(boolean showHome);
488
489 /**
490 * Set whether home should be displayed as an "up" affordance.
491 * Set this to true if selecting "home" returns up by a single level in your UI
492 * rather than back to the top level or front page.
493 *
494 * <p>To set several display options at once, see the setDisplayOptions methods.
495 *
496 * @param showHomeAsUp true to show the user that selecting home will return one
497 * level up rather than to the top level of the app.
498 *
499 * @see #setDisplayOptions(int)
500 * @see #setDisplayOptions(int, int)
501 */
502 public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
503
504 /**
505 * Set whether an activity title/subtitle should be displayed.
506 *
507 * <p>To set several display options at once, see the setDisplayOptions methods.
508 *
509 * @param showTitle true to display a title/subtitle if present.
510 *
511 * @see #setDisplayOptions(int)
512 * @see #setDisplayOptions(int, int)
513 */
514 public abstract void setDisplayShowTitleEnabled(boolean showTitle);
515
516 /**
517 * Set whether a custom view should be displayed, if set.
518 *
519 * <p>To set several display options at once, see the setDisplayOptions methods.
520 *
521 * @param showCustom true if the currently set custom view should be displayed, false otherwise.
522 *
523 * @see #setDisplayOptions(int)
524 * @see #setDisplayOptions(int, int)
525 */
526 public abstract void setDisplayShowCustomEnabled(boolean showCustom);
527
Adam Powella1700782010-05-13 13:27:35 -0700528 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700529 * Set the ActionBar's background. This will be used for the primary
530 * action bar.
Adam Powell33b97432010-04-20 10:01:14 -0700531 *
532 * @param d Background drawable
Adam Powellf88b9152011-09-07 14:54:32 -0700533 * @see #setStackedBackgroundDrawable(Drawable)
534 * @see #setSplitBackgroundDrawable(Drawable)
Adam Powell33b97432010-04-20 10:01:14 -0700535 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700536 public abstract void setBackgroundDrawable(@Nullable Drawable d);
Adam Powellef704442010-11-16 14:48:22 -0800537
538 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700539 * Set the ActionBar's stacked background. This will appear
540 * in the second row/stacked bar on some devices and configurations.
541 *
542 * @param d Background drawable for the stacked row
543 */
Adam Powell01453222011-09-07 16:13:36 -0700544 public void setStackedBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700545
546 /**
547 * Set the ActionBar's split background. This will appear in
548 * the split action bar containing menu-provided action buttons
549 * on some devices and configurations.
Scott Maine797ed62011-09-22 16:17:45 -0700550 * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
Adam Powellf88b9152011-09-07 14:54:32 -0700551 *
552 * @param d Background drawable for the split bar
553 */
Adam Powell01453222011-09-07 16:13:36 -0700554 public void setSplitBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700555
556 /**
Adam Powellef704442010-11-16 14:48:22 -0800557 * @return The current custom view.
558 */
559 public abstract View getCustomView();
560
Adam Powell33b97432010-04-20 10:01:14 -0700561 /**
Adam Powella4082912010-06-04 18:34:02 -0700562 * Returns the current ActionBar title in standard mode.
563 * Returns null if {@link #getNavigationMode()} would not return
564 * {@link #NAVIGATION_MODE_STANDARD}.
565 *
566 * @return The current ActionBar title or null.
Adam Powell33b97432010-04-20 10:01:14 -0700567 */
568 public abstract CharSequence getTitle();
569
570 /**
Adam Powella4082912010-06-04 18:34:02 -0700571 * Returns the current ActionBar subtitle in standard mode.
572 * Returns null if {@link #getNavigationMode()} would not return
573 * {@link #NAVIGATION_MODE_STANDARD}.
574 *
575 * @return The current ActionBar subtitle or null.
Adam Powell33b97432010-04-20 10:01:14 -0700576 */
577 public abstract CharSequence getSubtitle();
578
579 /**
Adam Powella4082912010-06-04 18:34:02 -0700580 * Returns the current navigation mode. The result will be one of:
581 * <ul>
582 * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
Adam Powell9ab97872010-10-26 21:47:29 -0700583 * <li>{@link #NAVIGATION_MODE_LIST}</li>
Adam Powella4082912010-06-04 18:34:02 -0700584 * <li>{@link #NAVIGATION_MODE_TABS}</li>
Adam Powella4082912010-06-04 18:34:02 -0700585 * </ul>
586 *
Adam Powell33b97432010-04-20 10:01:14 -0700587 * @return The current navigation mode.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700588 *
589 * @deprecated Action bar navigation modes are deprecated and not supported by inline
590 * toolbar action bars. Consider using other
591 * <a href="http://developer.android.com/design/patterns/navigation.html">common
592 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700593 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700594 @Deprecated
Tor Norbyed9273d62013-05-30 15:59:53 -0700595 @NavigationMode
Adam Powell33b97432010-04-20 10:01:14 -0700596 public abstract int getNavigationMode();
Adam Powell9ab97872010-10-26 21:47:29 -0700597
598 /**
599 * Set the current navigation mode.
600 *
601 * @param mode The new mode to set.
602 * @see #NAVIGATION_MODE_STANDARD
603 * @see #NAVIGATION_MODE_LIST
604 * @see #NAVIGATION_MODE_TABS
Adam Powellfc35dfd2014-03-17 17:44:59 -0700605 *
606 * @deprecated Action bar navigation modes are deprecated and not supported by inline
607 * toolbar action bars. Consider using other
608 * <a href="http://developer.android.com/design/patterns/navigation.html">common
609 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700610 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700611 @Deprecated
Tor Norbyed9273d62013-05-30 15:59:53 -0700612 public abstract void setNavigationMode(@NavigationMode int mode);
Adam Powell9ab97872010-10-26 21:47:29 -0700613
Adam Powell33b97432010-04-20 10:01:14 -0700614 /**
615 * @return The current set of display options.
616 */
617 public abstract int getDisplayOptions();
Adam Powell661c9082010-07-02 10:09:44 -0700618
619 /**
Adam Powell661c9082010-07-02 10:09:44 -0700620 * Create and return a new {@link Tab}.
621 * This tab will not be included in the action bar until it is added.
622 *
Dianne Hackborn2f048832011-06-16 13:31:57 -0700623 * <p>Very often tabs will be used to switch between {@link Fragment}
624 * objects. Here is a typical implementation of such tabs:</p>
625 *
626 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
627 * complete}
628 *
Adam Powell661c9082010-07-02 10:09:44 -0700629 * @return A new Tab
630 *
631 * @see #addTab(Tab)
Adam Powellfc35dfd2014-03-17 17:44:59 -0700632 *
633 * @deprecated Action bar navigation modes are deprecated and not supported by inline
634 * toolbar action bars. Consider using other
635 * <a href="http://developer.android.com/design/patterns/navigation.html">common
636 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700637 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700638 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700639 public abstract Tab newTab();
640
641 /**
642 * 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 -0700643 * If this is the first tab to be added it will become the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700644 *
645 * @param tab Tab to add
Adam Powellfc35dfd2014-03-17 17:44:59 -0700646 *
647 * @deprecated Action bar navigation modes are deprecated and not supported by inline
648 * toolbar action bars. Consider using other
649 * <a href="http://developer.android.com/design/patterns/navigation.html">common
650 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700651 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700652 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700653 public abstract void addTab(Tab tab);
654
655 /**
Adam Powell81b89442010-11-02 17:58:56 -0700656 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
657 *
658 * @param tab Tab to add
659 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700660 *
661 * @deprecated Action bar navigation modes are deprecated and not supported by inline
662 * toolbar action bars. Consider using other
663 * <a href="http://developer.android.com/design/patterns/navigation.html">common
664 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700665 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700666 @Deprecated
Adam Powell81b89442010-11-02 17:58:56 -0700667 public abstract void addTab(Tab tab, boolean setSelected);
668
669 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700670 * Add a tab for use in tabbed navigation mode. The tab will be inserted at
Adam Powell81b89442010-11-02 17:58:56 -0700671 * <code>position</code>. If this is the first tab to be added it will become
672 * the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700673 *
674 * @param tab The tab to add
675 * @param position The new position of the tab
Adam Powellfc35dfd2014-03-17 17:44:59 -0700676 *
677 * @deprecated Action bar navigation modes are deprecated and not supported by inline
678 * toolbar action bars. Consider using other
679 * <a href="http://developer.android.com/design/patterns/navigation.html">common
680 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700681 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700682 @Deprecated
Adam Powell2b6230e2010-09-07 17:55:25 -0700683 public abstract void addTab(Tab tab, int position);
Adam Powell661c9082010-07-02 10:09:44 -0700684
685 /**
Adam Powell81b89442010-11-02 17:58:56 -0700686 * Add a tab for use in tabbed navigation mode. The tab will be insterted at
687 * <code>position</code>.
688 *
689 * @param tab The tab to add
690 * @param position The new position of the tab
691 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700692 *
693 * @deprecated Action bar navigation modes are deprecated and not supported by inline
694 * toolbar action bars. Consider using other
695 * <a href="http://developer.android.com/design/patterns/navigation.html">common
696 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700697 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700698 @Deprecated
Adam Powell81b89442010-11-02 17:58:56 -0700699 public abstract void addTab(Tab tab, int position, boolean setSelected);
700
701 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700702 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
703 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700704 *
705 * @param tab The tab to remove
Adam Powellfc35dfd2014-03-17 17:44:59 -0700706 *
707 * @deprecated Action bar navigation modes are deprecated and not supported by inline
708 * toolbar action bars. Consider using other
709 * <a href="http://developer.android.com/design/patterns/navigation.html">common
710 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700711 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700712 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700713 public abstract void removeTab(Tab tab);
714
715 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700716 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
717 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700718 *
719 * @param position Position of the tab to remove
Adam Powellfc35dfd2014-03-17 17:44:59 -0700720 *
721 * @deprecated Action bar navigation modes are deprecated and not supported by inline
722 * toolbar action bars. Consider using other
723 * <a href="http://developer.android.com/design/patterns/navigation.html">common
724 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700725 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700726 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700727 public abstract void removeTabAt(int position);
728
729 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700730 * Remove all tabs from the action bar and deselect the current tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700731 *
732 * @deprecated Action bar navigation modes are deprecated and not supported by inline
733 * toolbar action bars. Consider using other
734 * <a href="http://developer.android.com/design/patterns/navigation.html">common
735 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700736 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700737 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700738 public abstract void removeAllTabs();
739
740 /**
Adam Powell661c9082010-07-02 10:09:44 -0700741 * Select the specified tab. If it is not a child of this action bar it will be added.
742 *
Adam Powell9ab97872010-10-26 21:47:29 -0700743 * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
744 *
Adam Powell661c9082010-07-02 10:09:44 -0700745 * @param tab Tab to select
Adam Powellfc35dfd2014-03-17 17:44:59 -0700746 *
747 * @deprecated Action bar navigation modes are deprecated and not supported by inline
748 * toolbar action bars. Consider using other
749 * <a href="http://developer.android.com/design/patterns/navigation.html">common
750 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700751 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700752 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -0700753 public abstract void selectTab(Tab tab);
754
755 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700756 * Returns the currently selected tab if in tabbed navigation mode and there is at least
757 * one tab present.
758 *
759 * @return The currently selected tab or null
Adam Powellfc35dfd2014-03-17 17:44:59 -0700760 *
761 * @deprecated Action bar navigation modes are deprecated and not supported by inline
762 * toolbar action bars. Consider using other
763 * <a href="http://developer.android.com/design/patterns/navigation.html">common
764 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -0700765 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700766 @Deprecated
Adam Powell2b6230e2010-09-07 17:55:25 -0700767 public abstract Tab getSelectedTab();
768
769 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700770 * Returns the tab at the specified index.
771 *
772 * @param index Index value in the range 0-get
773 * @return
Adam Powellfc35dfd2014-03-17 17:44:59 -0700774 *
775 * @deprecated Action bar navigation modes are deprecated and not supported by inline
776 * toolbar action bars. Consider using other
777 * <a href="http://developer.android.com/design/patterns/navigation.html">common
778 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700779 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700780 @Deprecated
Adam Powell9ab97872010-10-26 21:47:29 -0700781 public abstract Tab getTabAt(int index);
782
783 /**
Adam Powell0c24a552010-11-03 16:44:11 -0700784 * Returns the number of tabs currently registered with the action bar.
785 * @return Tab count
Adam Powellfc35dfd2014-03-17 17:44:59 -0700786 *
787 * @deprecated Action bar navigation modes are deprecated and not supported by inline
788 * toolbar action bars. Consider using other
789 * <a href="http://developer.android.com/design/patterns/navigation.html">common
790 * navigation patterns</a> instead.
Adam Powell0c24a552010-11-03 16:44:11 -0700791 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700792 @Deprecated
Adam Powell0c24a552010-11-03 16:44:11 -0700793 public abstract int getTabCount();
794
795 /**
Adam Powell6b336f82010-08-10 20:13:01 -0700796 * Retrieve the current height of the ActionBar.
797 *
798 * @return The ActionBar's height
799 */
800 public abstract int getHeight();
801
802 /**
803 * Show the ActionBar if it is not currently showing.
804 * If the window hosting the ActionBar does not have the feature
805 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
806 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700807 *
808 * <p>If you are hiding the ActionBar through
809 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN},
810 * you should not call this function directly.
Adam Powell6b336f82010-08-10 20:13:01 -0700811 */
812 public abstract void show();
813
814 /**
Scott Maine797ed62011-09-22 16:17:45 -0700815 * Hide the ActionBar if it is currently showing.
Adam Powell6b336f82010-08-10 20:13:01 -0700816 * If the window hosting the ActionBar does not have the feature
817 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
818 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700819 *
820 * <p>Instead of calling this function directly, you can also cause an
821 * ActionBar using the overlay feature to hide through
822 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}.
823 * Hiding the ActionBar through this system UI flag allows you to more
824 * seamlessly hide it in conjunction with other screen decorations.
Adam Powell6b336f82010-08-10 20:13:01 -0700825 */
826 public abstract void hide();
827
828 /**
829 * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
830 */
831 public abstract boolean isShowing();
832
833 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800834 * Add a listener that will respond to menu visibility change events.
835 *
836 * @param listener The new listener to add
Adam Powell89e06452010-06-23 20:24:52 -0700837 */
Adam Powell8515ee82010-11-30 14:09:55 -0800838 public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
839
840 /**
841 * Remove a menu visibility listener. This listener will no longer receive menu
842 * visibility change events.
843 *
844 * @param listener A listener to remove that was previously added
845 */
846 public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
847
848 /**
Adam Powellc29f4e52011-07-13 20:40:52 -0700849 * Enable or disable the "home" button in the corner of the action bar. (Note that this
850 * is the application home/up affordance on the action bar, not the systemwide home
851 * button.)
852 *
853 * <p>This defaults to true for packages targeting &lt; API 14. For packages targeting
854 * API 14 or greater, the application should call this method to enable interaction
855 * with the home/up affordance.
856 *
857 * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
858 * the home button.
859 *
860 * @param enabled true to enable the home button, false to disable the home button.
861 */
Adam Powell88ab6972011-07-28 11:25:01 -0700862 public void setHomeButtonEnabled(boolean enabled) { }
863
864 /**
865 * Returns a {@link Context} with an appropriate theme for creating views that
866 * will appear in the action bar. If you are inflating or instantiating custom views
867 * that will appear in an action bar, you should use the Context returned by this method.
868 * (This includes adapters used for list navigation mode.)
869 * This will ensure that views contrast properly against the action bar.
870 *
871 * @return A themed Context for creating views
872 */
873 public Context getThemedContext() { return null; }
Adam Powellc29f4e52011-07-13 20:40:52 -0700874
875 /**
Adam Powell27cba382013-01-22 18:55:20 -0800876 * Returns true if the Title field has been truncated during layout for lack
877 * of available space.
878 *
879 * @return true if the Title field has been truncated
880 * @hide pending API approval
881 */
882 public boolean isTitleTruncated() { return false; }
883
884 /**
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700885 * Set an alternate drawable to display next to the icon/logo/title
886 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
887 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
888 *
889 * <p>If you pass <code>null</code> to this method, the default drawable from the theme
890 * will be used.</p>
891 *
892 * <p>If you implement alternate or intermediate behavior around Up, you should also
893 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
894 * to provide a correct description of the action for accessibility support.</p>
895 *
896 * @param indicator A drawable to use for the up indicator, or null to use the theme's default
897 *
898 * @see #setDisplayOptions(int, int)
899 * @see #setDisplayHomeAsUpEnabled(boolean)
900 * @see #setHomeActionContentDescription(int)
901 */
902 public void setHomeAsUpIndicator(Drawable indicator) { }
903
904 /**
905 * Set an alternate drawable to display next to the icon/logo/title
906 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
907 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
908 *
909 * <p>If you pass <code>0</code> to this method, the default drawable from the theme
910 * will be used.</p>
911 *
912 * <p>If you implement alternate or intermediate behavior around Up, you should also
913 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
914 * to provide a correct description of the action for accessibility support.</p>
915 *
916 * @param resId Resource ID of a drawable to use for the up indicator, or null
917 * to use the theme's default
918 *
919 * @see #setDisplayOptions(int, int)
920 * @see #setDisplayHomeAsUpEnabled(boolean)
921 * @see #setHomeActionContentDescription(int)
922 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700923 public void setHomeAsUpIndicator(@DrawableRes int resId) { }
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700924
925 /**
926 * Set an alternate description for the Home/Up action, when enabled.
927 *
928 * <p>This description is commonly used for accessibility/screen readers when
929 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
930 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
931 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
932 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
933 * functionality such as a sliding drawer, you should also set this to accurately
934 * describe the action.</p>
935 *
936 * <p>Setting this to <code>null</code> will use the system default description.</p>
937 *
938 * @param description New description for the Home action when enabled
939 * @see #setHomeAsUpIndicator(int)
940 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
941 */
942 public void setHomeActionContentDescription(CharSequence description) { }
943
944 /**
945 * Set an alternate description for the Home/Up action, when enabled.
946 *
947 * <p>This description is commonly used for accessibility/screen readers when
948 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
949 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
950 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
951 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
952 * functionality such as a sliding drawer, you should also set this to accurately
953 * describe the action.</p>
954 *
955 * <p>Setting this to <code>0</code> will use the system default description.</p>
956 *
957 * @param resId Resource ID of a string to use as the new description
958 * for the Home action when enabled
959 * @see #setHomeAsUpIndicator(int)
960 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
961 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700962 public void setHomeActionContentDescription(@StringRes int resId) { }
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700963
Adam Powellb36e4f92014-05-01 10:23:33 -0700964 /**
965 * Enable hiding the action bar on content scroll.
966 *
967 * <p>If enabled, the action bar will scroll out of sight along with a
968 * {@link View#setNestedScrollingEnabled(boolean) nested scrolling child} view's content.
969 * The action bar must be in {@link Window#FEATURE_ACTION_BAR_OVERLAY overlay mode}
970 * to enable hiding on content scroll.</p>
971 *
972 * <p>When partially scrolled off screen the action bar is considered
973 * {@link #hide() hidden}. A call to {@link #show() show} will cause it to return to full view.
974 * </p>
975 * @param hideOnContentScroll true to enable hiding on content scroll.
976 */
977 public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
978 if (hideOnContentScroll) {
979 throw new UnsupportedOperationException("Hide on content scroll is not supported in " +
980 "this action bar configuration.");
981 }
982 }
983
984 /**
985 * Return whether the action bar is configured to scroll out of sight along with
986 * a {@link View#setNestedScrollingEnabled(boolean) nested scrolling child}.
987 *
988 * @return true if hide-on-content-scroll is enabled
989 * @see #setHideOnContentScrollEnabled(boolean)
990 */
991 public boolean isHideOnContentScrollEnabled() {
992 return false;
993 }
994
995 /**
996 * Return the current vertical offset of the action bar.
997 *
998 * <p>The action bar's current hide offset is the distance that the action bar is currently
999 * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
1000 * current measured {@link #getHeight() height} (fully invisible).</p>
1001 *
1002 * @return The action bar's offset toward its fully hidden state in pixels
1003 */
1004 public int getHideOffset() {
1005 return 0;
1006 }
1007
1008 /**
1009 * Set the current hide offset of the action bar.
1010 *
1011 * <p>The action bar's current hide offset is the distance that the action bar is currently
1012 * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
1013 * current measured {@link #getHeight() height} (fully invisible).</p>
1014 *
1015 * @param offset The action bar's offset toward its fully hidden state in pixels.
1016 */
1017 public void setHideOffset(int offset) {
1018 if (offset != 0) {
1019 throw new UnsupportedOperationException("Setting an explicit action bar hide offset " +
1020 "is not supported in this action bar configuration.");
1021 }
1022 }
1023
Adam Powell14d1fa42014-07-10 16:23:39 -07001024 /**
1025 * Set the Z-axis elevation of the action bar in pixels.
1026 *
1027 * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1028 * values are closer to the user.</p>
1029 *
1030 * @param elevation Elevation value in pixels
1031 */
1032 public void setElevation(float elevation) {
1033 if (elevation != 0) {
1034 throw new UnsupportedOperationException("Setting a non-zero elevation is " +
1035 "not supported in this action bar configuration.");
1036 }
1037 }
1038
1039 /**
1040 * Get the Z-axis elevation of the action bar in pixels.
1041 *
1042 * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1043 * values are closer to the user.</p>
1044 *
1045 * @return Elevation value in pixels
1046 */
1047 public float getElevation() {
1048 return 0;
1049 }
1050
Adam Powelle43340c2014-03-17 19:10:43 -07001051 /** @hide */
1052 public void setDefaultDisplayHomeAsUpEnabled(boolean enabled) {
1053 }
1054
1055 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001056 @UnsupportedAppUsage
Adam Powelle43340c2014-03-17 19:10:43 -07001057 public void setShowHideAnimationEnabled(boolean enabled) {
1058 }
1059
1060 /** @hide */
1061 public void onConfigurationChanged(Configuration config) {
1062 }
1063
1064 /** @hide */
1065 public void dispatchMenuVisibilityChanged(boolean visible) {
1066 }
1067
1068 /** @hide */
Adam Powelle43340c2014-03-17 19:10:43 -07001069 public ActionMode startActionMode(ActionMode.Callback callback) {
1070 return null;
1071 }
1072
Adam Powell07a74542014-05-30 15:52:44 -07001073 /** @hide */
1074 public boolean openOptionsMenu() {
1075 return false;
1076 }
1077
1078 /** @hide */
Evan Rosky41823d12017-03-21 14:42:35 -07001079 public boolean closeOptionsMenu() {
1080 return false;
1081 }
1082
1083 /** @hide */
Adam Powell07a74542014-05-30 15:52:44 -07001084 public boolean invalidateOptionsMenu() {
1085 return false;
1086 }
1087
1088 /** @hide */
1089 public boolean onMenuKeyEvent(KeyEvent event) {
1090 return false;
1091 }
1092
1093 /** @hide */
Abodunrinwa Tokia04b7ad2015-06-30 17:44:04 -07001094 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
1095 return false;
1096 }
1097
1098 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001099 @UnsupportedAppUsage
Adam Powell07a74542014-05-30 15:52:44 -07001100 public boolean collapseActionView() {
1101 return false;
1102 }
1103
Adam Powellaf2d8592014-08-26 18:06:40 -07001104 /** @hide */
1105 public void setWindowTitle(CharSequence title) {
1106 }
1107
Chris Banes21b25772016-01-04 20:41:59 +00001108 /** @hide */
1109 public void onDestroy() {
1110 }
1111
George Mount5beb26172015-12-15 13:36:01 -08001112 /**
Adam Powell8515ee82010-11-30 14:09:55 -08001113 * Listener interface for ActionBar navigation events.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001114 *
1115 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1116 * toolbar action bars. Consider using other
1117 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1118 * navigation patterns</a> instead.
Adam Powell8515ee82010-11-30 14:09:55 -08001119 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07001120 @Deprecated
Adam Powell8515ee82010-11-30 14:09:55 -08001121 public interface OnNavigationListener {
Adam Powell33b97432010-04-20 10:01:14 -07001122 /**
Adam Powella4082912010-06-04 18:34:02 -07001123 * This method is called whenever a navigation item in your action bar
1124 * is selected.
1125 *
1126 * @param itemPosition Position of the item clicked.
1127 * @param itemId ID of the item clicked.
1128 * @return True if the event was handled, false otherwise.
1129 */
1130 public boolean onNavigationItemSelected(int itemPosition, long itemId);
Adam Powell33b97432010-04-20 10:01:14 -07001131 }
Adam Powell661c9082010-07-02 10:09:44 -07001132
1133 /**
Adam Powell8515ee82010-11-30 14:09:55 -08001134 * Listener for receiving events when action bar menus are shown or hidden.
1135 */
1136 public interface OnMenuVisibilityListener {
1137 /**
1138 * Called when an action bar menu is shown or hidden. Applications may want to use
1139 * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
1140 * gameplay, or other activity within the main content area.
1141 *
1142 * @param isVisible True if an action bar menu is now visible, false if no action bar
1143 * menus are visible.
1144 */
1145 public void onMenuVisibilityChanged(boolean isVisible);
1146 }
1147
1148 /**
Adam Powell661c9082010-07-02 10:09:44 -07001149 * A tab in the action bar.
1150 *
1151 * <p>Tabs manage the hiding and showing of {@link Fragment}s.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001152 *
1153 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1154 * toolbar action bars. Consider using other
1155 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1156 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -07001157 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07001158 @Deprecated
Adam Powell661c9082010-07-02 10:09:44 -07001159 public static abstract class Tab {
1160 /**
1161 * An invalid position for a tab.
1162 *
1163 * @see #getPosition()
1164 */
1165 public static final int INVALID_POSITION = -1;
1166
1167 /**
1168 * Return the current position of this tab in the action bar.
1169 *
1170 * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
1171 * the action bar.
1172 */
1173 public abstract int getPosition();
1174
1175 /**
1176 * Return the icon associated with this tab.
1177 *
1178 * @return The tab's icon
1179 */
1180 public abstract Drawable getIcon();
1181
1182 /**
1183 * Return the text of this tab.
1184 *
1185 * @return The tab's text
1186 */
1187 public abstract CharSequence getText();
1188
1189 /**
1190 * Set the icon displayed on this tab.
1191 *
1192 * @param icon The drawable to use as an icon
Adam Powell9ab97872010-10-26 21:47:29 -07001193 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001194 */
Adam Powell9ab97872010-10-26 21:47:29 -07001195 public abstract Tab setIcon(Drawable icon);
Adam Powell661c9082010-07-02 10:09:44 -07001196
1197 /**
Adam Powell32555f32010-11-17 13:49:22 -08001198 * Set the icon displayed on this tab.
1199 *
1200 * @param resId Resource ID referring to the drawable to use as an icon
1201 * @return The current instance for call chaining
1202 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001203 public abstract Tab setIcon(@DrawableRes int resId);
Adam Powell32555f32010-11-17 13:49:22 -08001204
1205 /**
Adam Powell661c9082010-07-02 10:09:44 -07001206 * Set the text displayed on this tab. Text may be truncated if there is not
1207 * room to display the entire string.
1208 *
1209 * @param text The text to display
Adam Powell9ab97872010-10-26 21:47:29 -07001210 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001211 */
Adam Powell9ab97872010-10-26 21:47:29 -07001212 public abstract Tab setText(CharSequence text);
Adam Powell661c9082010-07-02 10:09:44 -07001213
1214 /**
Adam Powell32555f32010-11-17 13:49:22 -08001215 * Set the text displayed on this tab. Text may be truncated if there is not
1216 * room to display the entire string.
1217 *
1218 * @param resId A resource ID referring to the text that should be displayed
1219 * @return The current instance for call chaining
1220 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001221 public abstract Tab setText(@StringRes int resId);
Adam Powell32555f32010-11-17 13:49:22 -08001222
1223 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001224 * Set a custom view to be used for this tab. This overrides values set by
1225 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
Adam Powell661c9082010-07-02 10:09:44 -07001226 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001227 * @param view Custom view to be used as a tab.
Adam Powell9ab97872010-10-26 21:47:29 -07001228 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001229 */
Adam Powell9ab97872010-10-26 21:47:29 -07001230 public abstract Tab setCustomView(View view);
Adam Powell661c9082010-07-02 10:09:44 -07001231
1232 /**
Adam Powell32555f32010-11-17 13:49:22 -08001233 * Set a custom view to be used for this tab. This overrides values set by
1234 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
1235 *
1236 * @param layoutResId A layout resource to inflate and use as a custom tab view
1237 * @return The current instance for call chaining
1238 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001239 public abstract Tab setCustomView(@LayoutRes int layoutResId);
Adam Powell32555f32010-11-17 13:49:22 -08001240
1241 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001242 * Retrieve a previously set custom view for this tab.
Adam Powell661c9082010-07-02 10:09:44 -07001243 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001244 * @return The custom view set by {@link #setCustomView(View)}.
Adam Powell661c9082010-07-02 10:09:44 -07001245 */
Adam Powell2b6230e2010-09-07 17:55:25 -07001246 public abstract View getCustomView();
1247
1248 /**
1249 * Give this Tab an arbitrary object to hold for later use.
1250 *
1251 * @param obj Object to store
Adam Powell9ab97872010-10-26 21:47:29 -07001252 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001253 */
Adam Powell9ab97872010-10-26 21:47:29 -07001254 public abstract Tab setTag(Object obj);
Adam Powell2b6230e2010-09-07 17:55:25 -07001255
1256 /**
1257 * @return This Tab's tag object.
1258 */
1259 public abstract Object getTag();
1260
1261 /**
1262 * Set the {@link TabListener} that will handle switching to and from this tab.
1263 * All tabs must have a TabListener set before being added to the ActionBar.
1264 *
1265 * @param listener Listener to handle tab selection events
Adam Powell9ab97872010-10-26 21:47:29 -07001266 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001267 */
Adam Powell9ab97872010-10-26 21:47:29 -07001268 public abstract Tab setTabListener(TabListener listener);
Adam Powell661c9082010-07-02 10:09:44 -07001269
1270 /**
1271 * Select this tab. Only valid if the tab has been added to the action bar.
1272 */
1273 public abstract void select();
Adam Powell94e56ef2011-09-06 21:22:22 -07001274
1275 /**
1276 * Set a description of this tab's content for use in accessibility support.
1277 * If no content description is provided the title will be used.
1278 *
1279 * @param resId A resource ID referring to the description text
1280 * @return The current instance for call chaining
1281 * @see #setContentDescription(CharSequence)
1282 * @see #getContentDescription()
1283 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001284 public abstract Tab setContentDescription(@StringRes int resId);
Adam Powell94e56ef2011-09-06 21:22:22 -07001285
1286 /**
1287 * Set a description of this tab's content for use in accessibility support.
1288 * If no content description is provided the title will be used.
1289 *
1290 * @param contentDesc Description of this tab's content
1291 * @return The current instance for call chaining
1292 * @see #setContentDescription(int)
1293 * @see #getContentDescription()
1294 */
1295 public abstract Tab setContentDescription(CharSequence contentDesc);
1296
1297 /**
1298 * Gets a brief description of this tab's content for use in accessibility support.
1299 *
1300 * @return Description of this tab's content
1301 * @see #setContentDescription(CharSequence)
1302 * @see #setContentDescription(int)
1303 */
1304 public abstract CharSequence getContentDescription();
Adam Powell661c9082010-07-02 10:09:44 -07001305 }
Adam Powell2b6230e2010-09-07 17:55:25 -07001306
1307 /**
1308 * Callback interface invoked when a tab is focused, unfocused, added, or removed.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001309 *
1310 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1311 * toolbar action bars. Consider using other
1312 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1313 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -07001314 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07001315 @Deprecated
Adam Powell2b6230e2010-09-07 17:55:25 -07001316 public interface TabListener {
1317 /**
1318 * Called when a tab enters the selected state.
1319 *
1320 * @param tab The tab that was selected
1321 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1322 * during a tab switch. The previous tab's unselect and this tab's select will be
Adam Powell0c24a552010-11-03 16:44:11 -07001323 * executed in a single transaction. This FragmentTransaction does not support
1324 * being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001325 */
1326 public void onTabSelected(Tab tab, FragmentTransaction ft);
1327
1328 /**
1329 * Called when a tab exits the selected state.
1330 *
1331 * @param tab The tab that was unselected
1332 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1333 * during a tab switch. This tab's unselect and the newly selected tab's select
Adam Powell0c24a552010-11-03 16:44:11 -07001334 * will be executed in a single transaction. This FragmentTransaction does not
1335 * support being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001336 */
1337 public void onTabUnselected(Tab tab, FragmentTransaction ft);
Adam Powell7f9b9052010-10-19 16:56:07 -07001338
1339 /**
1340 * Called when a tab that is already selected is chosen again by the user.
1341 * Some applications may use this action to return to the top level of a category.
1342 *
1343 * @param tab The tab that was reselected.
1344 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
Adam Powell0c24a552010-11-03 16:44:11 -07001345 * once this method returns. This FragmentTransaction does not support
1346 * being added to the back stack.
Adam Powell7f9b9052010-10-19 16:56:07 -07001347 */
1348 public void onTabReselected(Tab tab, FragmentTransaction ft);
Adam Powell2b6230e2010-09-07 17:55:25 -07001349 }
Adam Powell9ab97872010-10-26 21:47:29 -07001350
1351 /**
1352 * Per-child layout information associated with action bar custom views.
1353 *
1354 * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
1355 */
Adam Powelle43340c2014-03-17 19:10:43 -07001356 public static class LayoutParams extends ViewGroup.MarginLayoutParams {
Adam Powell9ab97872010-10-26 21:47:29 -07001357 /**
1358 * Gravity for the view associated with these LayoutParams.
1359 *
1360 * @see android.view.Gravity
1361 */
1362 @ViewDebug.ExportedProperty(category = "layout", mapping = {
Adam Powelle43340c2014-03-17 19:10:43 -07001363 @ViewDebug.IntToString(from = -1, to = "NONE"),
1364 @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"),
1365 @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
1366 @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
1367 @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"),
1368 @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"),
1369 @ViewDebug.IntToString(from = Gravity.START, to = "START"),
1370 @ViewDebug.IntToString(from = Gravity.END, to = "END"),
1371 @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"),
1372 @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"),
1373 @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
1374 @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"),
1375 @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
1376 @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
Adam Powell9ab97872010-10-26 21:47:29 -07001377 })
Ashley Rosede3b4a72019-03-04 16:44:07 -05001378 @InspectableProperty(
1379 name = "layout_gravity",
1380 valueType = InspectableProperty.ValueType.GRAVITY)
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001381 public int gravity = Gravity.NO_GRAVITY;
Adam Powell9ab97872010-10-26 21:47:29 -07001382
Tor Norbyed9273d62013-05-30 15:59:53 -07001383 public LayoutParams(@NonNull Context c, AttributeSet attrs) {
Adam Powell9ab97872010-10-26 21:47:29 -07001384 super(c, attrs);
Adam Powellb226bea2014-04-04 12:23:42 -07001385
1386 TypedArray a = c.obtainStyledAttributes(attrs,
1387 com.android.internal.R.styleable.ActionBar_LayoutParams);
1388 gravity = a.getInt(
1389 com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity,
1390 Gravity.NO_GRAVITY);
1391 a.recycle();
Adam Powell9ab97872010-10-26 21:47:29 -07001392 }
1393
1394 public LayoutParams(int width, int height) {
1395 super(width, height);
Adam Powelle021e6e2014-05-23 17:27:24 -07001396 this.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
Adam Powell9ab97872010-10-26 21:47:29 -07001397 }
1398
1399 public LayoutParams(int width, int height, int gravity) {
1400 super(width, height);
Alan Viveretteda4bd6f2014-04-14 12:58:34 -07001401
1402 this.gravity = gravity;
Adam Powell9ab97872010-10-26 21:47:29 -07001403 }
1404
1405 public LayoutParams(int gravity) {
1406 this(WRAP_CONTENT, MATCH_PARENT, gravity);
1407 }
1408
1409 public LayoutParams(LayoutParams source) {
1410 super(source);
Adam Powelle021e6e2014-05-23 17:27:24 -07001411 this.gravity = source.gravity;
Adam Powell9ab97872010-10-26 21:47:29 -07001412 }
1413
1414 public LayoutParams(ViewGroup.LayoutParams source) {
1415 super(source);
1416 }
Adam Powelle43340c2014-03-17 19:10:43 -07001417
Adam Powelld7600832014-07-01 15:22:50 -07001418 /*
1419 * Note for framework developers:
1420 *
1421 * You might notice that ActionBar.LayoutParams is missing a constructor overload
1422 * for MarginLayoutParams. While it may seem like a good idea to add one, at this
1423 * point it's dangerous for source compatibility. Upon building against a new
1424 * version of the SDK an app can end up statically linking to the new MarginLayoutParams
1425 * overload, causing a crash when running on older platform versions with no other changes.
1426 */
Siva Velusamy94a6d152015-05-05 15:07:00 -07001427
1428 /** @hide */
1429 @Override
1430 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
1431 super.encodeProperties(encoder);
1432
1433 encoder.addProperty("gravity", gravity);
1434 }
Adam Powell9ab97872010-10-26 21:47:29 -07001435 }
Adam Powell33b97432010-04-20 10:01:14 -07001436}