blob: 6fc0d74b5f183e98bb56c12bc9c6af5d54844a42 [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;
Adam Powell9ab97872010-10-26 21:47:29 -070025import android.content.Context;
Adam Powelle43340c2014-03-17 19:10:43 -070026import android.content.res.Configuration;
Adam Powell9ab97872010-10-26 21:47:29 -070027import android.content.res.TypedArray;
Adam Powell33b97432010-04-20 10:01:14 -070028import android.graphics.drawable.Drawable;
Adam Powell9ab97872010-10-26 21:47:29 -070029import android.util.AttributeSet;
Adam Powelle43340c2014-03-17 19:10:43 -070030import android.view.ActionMode;
Adam Powell9ab97872010-10-26 21:47:29 -070031import android.view.Gravity;
Adam Powell07a74542014-05-30 15:52:44 -070032import android.view.KeyEvent;
Adam Powell33b97432010-04-20 10:01:14 -070033import android.view.View;
George Mount5beb26172015-12-15 13:36:01 -080034import android.view.View.OnFocusChangeListener;
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;
George Mount5beb26172015-12-15 13:36:01 -080038import android.view.ViewParent;
Adam Powell6b336f82010-08-10 20:13:01 -070039import android.view.Window;
Adam Powella4082912010-06-04 18:34:02 -070040import android.widget.SpinnerAdapter;
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)
99 @IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
100 public @interface NavigationMode {}
101
Adam Powella1700782010-05-13 13:27:35 -0700102 /**
Adam Powella4082912010-06-04 18:34:02 -0700103 * Standard navigation mode. Consists of either a logo or icon
Adam Powella1700782010-05-13 13:27:35 -0700104 * and title text with an optional subtitle. Clicking any of these elements
Adam Powellcf035762010-12-06 11:49:45 -0800105 * will dispatch onOptionsItemSelected to the host Activity with
Adam Powella1700782010-05-13 13:27:35 -0700106 * a MenuItem with item ID android.R.id.home.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700107 *
108 * @deprecated Action bar navigation modes are deprecated and not supported by inline
109 * toolbar action bars. Consider using other
110 * <a href="http://developer.android.com/design/patterns/navigation.html">common
111 * navigation patterns</a> instead.
Adam Powella1700782010-05-13 13:27:35 -0700112 */
Adam Powella4082912010-06-04 18:34:02 -0700113 public static final int NAVIGATION_MODE_STANDARD = 0;
Adam Powell33b97432010-04-20 10:01:14 -0700114
115 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700116 * List navigation mode. Instead of static title text this mode
117 * presents a list menu for navigation within the activity.
118 * e.g. this might be presented to the user as a dropdown list.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700119 *
120 * @deprecated Action bar navigation modes are deprecated and not supported by inline
121 * toolbar action bars. Consider using other
122 * <a href="http://developer.android.com/design/patterns/navigation.html">common
123 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700124 */
Adam Powell9ab97872010-10-26 21:47:29 -0700125 public static final int NAVIGATION_MODE_LIST = 1;
Adam Powell33b97432010-04-20 10:01:14 -0700126
127 /**
128 * Tab navigation mode. Instead of static title text this mode
129 * presents a series of tabs for navigation within the activity.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700130 *
131 * @deprecated Action bar navigation modes are deprecated and not supported by inline
132 * toolbar action bars. Consider using other
133 * <a href="http://developer.android.com/design/patterns/navigation.html">common
134 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700135 */
136 public static final int NAVIGATION_MODE_TABS = 2;
Adam Powell33b97432010-04-20 10:01:14 -0700137
Tor Norbyed9273d62013-05-30 15:59:53 -0700138 /** @hide */
139 @Retention(RetentionPolicy.SOURCE)
140 @IntDef(flag = true,
141 value = {
142 DISPLAY_USE_LOGO,
143 DISPLAY_SHOW_HOME,
144 DISPLAY_HOME_AS_UP,
145 DISPLAY_SHOW_TITLE,
146 DISPLAY_SHOW_CUSTOM,
147 DISPLAY_TITLE_MULTIPLE_LINES
148 })
149 public @interface DisplayOptions {}
150
Adam Powell33b97432010-04-20 10:01:14 -0700151 /**
152 * Use logo instead of icon if available. This flag will cause appropriate
153 * navigation modes to use a wider logo in place of the standard icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700154 *
155 * @see #setDisplayOptions(int)
156 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700157 */
158 public static final int DISPLAY_USE_LOGO = 0x1;
159
160 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700161 * Show 'home' elements in this action bar, leaving more space for other
Adam Powell33b97432010-04-20 10:01:14 -0700162 * navigation elements. This includes logo and icon.
Adam Powell9ab97872010-10-26 21:47:29 -0700163 *
164 * @see #setDisplayOptions(int)
165 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700166 */
Adam Powell9ab97872010-10-26 21:47:29 -0700167 public static final int DISPLAY_SHOW_HOME = 0x2;
168
169 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700170 * Display the 'home' element such that it appears as an 'up' affordance.
171 * e.g. show an arrow to the left indicating the action that will be taken.
172 *
173 * Set this flag if selecting the 'home' button in the action bar to return
174 * up by a single level in your UI rather than back to the top level or front page.
175 *
Adam Powellc29f4e52011-07-13 20:40:52 -0700176 * <p>Setting this option will implicitly enable interaction with the home/up
177 * button. See {@link #setHomeButtonEnabled(boolean)}.
178 *
Adam Powell9ab97872010-10-26 21:47:29 -0700179 * @see #setDisplayOptions(int)
180 * @see #setDisplayOptions(int, int)
181 */
182 public static final int DISPLAY_HOME_AS_UP = 0x4;
183
184 /**
185 * Show the activity title and subtitle, if present.
186 *
187 * @see #setTitle(CharSequence)
188 * @see #setTitle(int)
189 * @see #setSubtitle(CharSequence)
190 * @see #setSubtitle(int)
191 * @see #setDisplayOptions(int)
192 * @see #setDisplayOptions(int, int)
193 */
194 public static final int DISPLAY_SHOW_TITLE = 0x8;
195
196 /**
197 * Show the custom view if one has been set.
198 * @see #setCustomView(View)
199 * @see #setDisplayOptions(int)
200 * @see #setDisplayOptions(int, int)
201 */
202 public static final int DISPLAY_SHOW_CUSTOM = 0x10;
203
204 /**
Adam Powell27cba382013-01-22 18:55:20 -0800205 * Allow the title to wrap onto multiple lines if space is available
206 * @hide pending API approval
207 */
208 public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20;
209
210 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700211 * Set the action bar into custom navigation mode, supplying a view
212 * for custom navigation.
213 *
214 * Custom navigation views appear between the application icon and
215 * any action buttons and may use any space available there. Common
216 * use cases for custom navigation views might include an auto-suggesting
217 * address bar for a browser or other navigation mechanisms that do not
218 * translate well to provided navigation modes.
219 *
220 * @param view Custom navigation view to place in the ActionBar.
221 */
222 public abstract void setCustomView(View view);
Adam Powell89e06452010-06-23 20:24:52 -0700223
Adam Powell33b97432010-04-20 10:01:14 -0700224 /**
Adam Powella4082912010-06-04 18:34:02 -0700225 * Set the action bar into custom navigation mode, supplying a view
226 * for custom navigation.
Adam Powell33b97432010-04-20 10:01:14 -0700227 *
Adam Powellef704442010-11-16 14:48:22 -0800228 * <p>Custom navigation views appear between the application icon and
Adam Powell33b97432010-04-20 10:01:14 -0700229 * any action buttons and may use any space available there. Common
Adam Powella4082912010-06-04 18:34:02 -0700230 * use cases for custom navigation views might include an auto-suggesting
231 * address bar for a browser or other navigation mechanisms that do not
Adam Powellef704442010-11-16 14:48:22 -0800232 * translate well to provided navigation modes.</p>
233 *
234 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
235 * the custom view to be displayed.</p>
Adam Powell33b97432010-04-20 10:01:14 -0700236 *
237 * @param view Custom navigation view to place in the ActionBar.
Adam Powell9ab97872010-10-26 21:47:29 -0700238 * @param layoutParams How this custom view should layout in the bar.
Adam Powellef704442010-11-16 14:48:22 -0800239 *
240 * @see #setDisplayOptions(int, int)
Adam Powell33b97432010-04-20 10:01:14 -0700241 */
Adam Powell9ab97872010-10-26 21:47:29 -0700242 public abstract void setCustomView(View view, LayoutParams layoutParams);
243
244 /**
Adam Powell3f476b32011-01-03 19:25:36 -0800245 * Set the action bar into custom navigation mode, supplying a view
246 * for custom navigation.
247 *
248 * <p>Custom navigation views appear between the application icon and
249 * any action buttons and may use any space available there. Common
250 * use cases for custom navigation views might include an auto-suggesting
251 * address bar for a browser or other navigation mechanisms that do not
252 * translate well to provided navigation modes.</p>
253 *
254 * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
255 * the custom view to be displayed.</p>
256 *
257 * @param resId Resource ID of a layout to inflate into the ActionBar.
258 *
259 * @see #setDisplayOptions(int, int)
260 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700261 public abstract void setCustomView(@LayoutRes int resId);
Adam Powell3f476b32011-01-03 19:25:36 -0800262
263 /**
Adam Powell1969b872011-03-22 11:52:48 -0700264 * Set the icon to display in the 'home' section of the action bar.
265 * The action bar will use an icon specified by its style or the
266 * activity icon by default.
267 *
268 * Whether the home section shows an icon or logo is controlled
269 * by the display option {@link #DISPLAY_USE_LOGO}.
270 *
271 * @param resId Resource ID of a drawable to show as an icon.
272 *
273 * @see #setDisplayUseLogoEnabled(boolean)
274 * @see #setDisplayShowHomeEnabled(boolean)
275 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700276 public abstract void setIcon(@DrawableRes int resId);
Adam Powell1969b872011-03-22 11:52:48 -0700277
278 /**
279 * Set the icon to display in the 'home' section of the action bar.
280 * The action bar will use an icon specified by its style or the
281 * activity icon by default.
282 *
283 * Whether the home section shows an icon or logo is controlled
284 * by the display option {@link #DISPLAY_USE_LOGO}.
285 *
286 * @param icon Drawable to show as an icon.
287 *
288 * @see #setDisplayUseLogoEnabled(boolean)
289 * @see #setDisplayShowHomeEnabled(boolean)
290 */
291 public abstract void setIcon(Drawable icon);
292
293 /**
294 * Set the logo to display in the 'home' section of the action bar.
295 * The action bar will use a logo specified by its style or the
296 * activity logo by default.
297 *
298 * Whether the home section shows an icon or logo is controlled
299 * by the display option {@link #DISPLAY_USE_LOGO}.
300 *
301 * @param resId Resource ID of a drawable to show as a logo.
302 *
303 * @see #setDisplayUseLogoEnabled(boolean)
304 * @see #setDisplayShowHomeEnabled(boolean)
305 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700306 public abstract void setLogo(@DrawableRes int resId);
Adam Powell1969b872011-03-22 11:52:48 -0700307
308 /**
309 * Set the logo to display in the 'home' section of the action bar.
310 * The action bar will use a logo specified by its style or the
311 * activity logo by default.
312 *
313 * Whether the home section shows an icon or logo is controlled
314 * by the display option {@link #DISPLAY_USE_LOGO}.
315 *
316 * @param logo Drawable to show as a logo.
317 *
318 * @see #setDisplayUseLogoEnabled(boolean)
319 * @see #setDisplayShowHomeEnabled(boolean)
320 */
321 public abstract void setLogo(Drawable logo);
322
323 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700324 * Set the adapter and navigation callback for list navigation mode.
325 *
326 * The supplied adapter will provide views for the expanded list as well as
327 * the currently selected item. (These may be displayed differently.)
328 *
Adam Powell8515ee82010-11-30 14:09:55 -0800329 * The supplied OnNavigationListener will alert the application when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700330 * changes the current list selection.
331 *
332 * @param adapter An adapter that will provide views both to display
333 * the current navigation selection and populate views
334 * within the dropdown navigation menu.
Adam Powell8515ee82010-11-30 14:09:55 -0800335 * @param callback An OnNavigationListener that will receive events when the user
Adam Powell9ab97872010-10-26 21:47:29 -0700336 * selects a navigation item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700337 *
338 * @deprecated Action bar navigation modes are deprecated and not supported by inline
339 * toolbar action bars. Consider using other
340 * <a href="http://developer.android.com/design/patterns/navigation.html">common
341 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700342 */
343 public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
Adam Powell8515ee82010-11-30 14:09:55 -0800344 OnNavigationListener callback);
Adam Powell9ab97872010-10-26 21:47:29 -0700345
346 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700347 * Set the selected navigation item in list or tabbed navigation modes.
Adam Powell17809772010-07-21 13:25:11 -0700348 *
349 * @param position Position of the item to select.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700350 *
351 * @deprecated Action bar navigation modes are deprecated and not supported by inline
352 * toolbar action bars. Consider using other
353 * <a href="http://developer.android.com/design/patterns/navigation.html">common
354 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700355 */
356 public abstract void setSelectedNavigationItem(int position);
357
358 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700359 * Get the position of the selected navigation item in list or tabbed navigation modes.
360 *
361 * @return Position of the selected item.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700362 *
363 * @deprecated Action bar navigation modes are deprecated and not supported by inline
364 * toolbar action bars. Consider using other
365 * <a href="http://developer.android.com/design/patterns/navigation.html">common
366 * navigation patterns</a> instead.
Adam Powell17809772010-07-21 13:25:11 -0700367 */
Adam Powell9ab97872010-10-26 21:47:29 -0700368 public abstract int getSelectedNavigationIndex();
369
370 /**
371 * Get the number of navigation items present in the current navigation mode.
372 *
373 * @return Number of navigation items.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700374 *
375 * @deprecated Action bar navigation modes are deprecated and not supported by inline
376 * toolbar action bars. Consider using other
377 * <a href="http://developer.android.com/design/patterns/navigation.html">common
378 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700379 */
380 public abstract int getNavigationItemCount();
Adam Powell17809772010-07-21 13:25:11 -0700381
382 /**
Adam Powellef704442010-11-16 14:48:22 -0800383 * Set the action bar's title. This will only be displayed if
384 * {@link #DISPLAY_SHOW_TITLE} is set.
Adam Powell0e94b512010-06-29 17:58:20 -0700385 *
386 * @param title Title to set
Adam Powella66c7b02010-07-28 15:28:25 -0700387 *
388 * @see #setTitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800389 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700390 */
391 public abstract void setTitle(CharSequence title);
392
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 Powella66c7b02010-07-28 15:28:25 -0700396 *
397 * @param resId Resource ID of title string to set
398 *
399 * @see #setTitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800400 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700401 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700402 public abstract void setTitle(@StringRes int resId);
Adam Powella66c7b02010-07-28 15:28:25 -0700403
404 /**
Adam Powellef704442010-11-16 14:48:22 -0800405 * Set the action bar's subtitle. This will only be displayed if
406 * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
407 * subtitle entirely.
Adam Powell0e94b512010-06-29 17:58:20 -0700408 *
409 * @param subtitle Subtitle to set
Adam Powella66c7b02010-07-28 15:28:25 -0700410 *
411 * @see #setSubtitle(int)
Adam Powellef704442010-11-16 14:48:22 -0800412 * @see #setDisplayOptions(int, int)
Adam Powell0e94b512010-06-29 17:58:20 -0700413 */
414 public abstract void setSubtitle(CharSequence subtitle);
415
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.
Adam Powella66c7b02010-07-28 15:28:25 -0700419 *
420 * @param resId Resource ID of subtitle string to set
421 *
422 * @see #setSubtitle(CharSequence)
Adam Powellef704442010-11-16 14:48:22 -0800423 * @see #setDisplayOptions(int, int)
Adam Powella66c7b02010-07-28 15:28:25 -0700424 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700425 public abstract void setSubtitle(@StringRes int resId);
Adam Powella66c7b02010-07-28 15:28:25 -0700426
427 /**
Adam Powella1700782010-05-13 13:27:35 -0700428 * Set display options. This changes all display option bits at once. To change
429 * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
Adam Powell33b97432010-04-20 10:01:14 -0700430 *
431 * @param options A combination of the bits defined by the DISPLAY_ constants
432 * defined in ActionBar.
433 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700434 public abstract void setDisplayOptions(@DisplayOptions int options);
Adam Powell33b97432010-04-20 10:01:14 -0700435
436 /**
Adam Powella1700782010-05-13 13:27:35 -0700437 * Set selected display options. Only the options specified by mask will be changed.
438 * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
439 *
Adam Powell9ab97872010-10-26 21:47:29 -0700440 * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
441 * {@link #DISPLAY_SHOW_HOME} option.
Ben Komalo5ad7af62010-11-01 12:04:51 -0700442 * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
Adam Powell9ab97872010-10-26 21:47:29 -0700443 * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
Adam Powella1700782010-05-13 13:27:35 -0700444 *
445 * @param options A combination of the bits defined by the DISPLAY_ constants
446 * defined in ActionBar.
447 * @param mask A bit mask declaring which display options should be changed.
448 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700449 public abstract void setDisplayOptions(@DisplayOptions int options, @DisplayOptions int mask);
Adam Powell3f476b32011-01-03 19:25:36 -0800450
451 /**
452 * Set whether to display the activity logo rather than the activity icon.
453 * A logo is often a wider, more detailed image.
454 *
455 * <p>To set several display options at once, see the setDisplayOptions methods.
456 *
457 * @param useLogo true to use the activity logo, false to use the activity icon.
458 *
459 * @see #setDisplayOptions(int)
460 * @see #setDisplayOptions(int, int)
461 */
462 public abstract void setDisplayUseLogoEnabled(boolean useLogo);
463
464 /**
465 * Set whether to include the application home affordance in the action bar.
466 * Home is presented as either an activity icon or logo.
467 *
468 * <p>To set several display options at once, see the setDisplayOptions methods.
469 *
470 * @param showHome true to show home, false otherwise.
471 *
472 * @see #setDisplayOptions(int)
473 * @see #setDisplayOptions(int, int)
474 */
475 public abstract void setDisplayShowHomeEnabled(boolean showHome);
476
477 /**
478 * Set whether home should be displayed as an "up" affordance.
479 * Set this to true if selecting "home" returns up by a single level in your UI
480 * rather than back to the top level or front page.
481 *
482 * <p>To set several display options at once, see the setDisplayOptions methods.
483 *
484 * @param showHomeAsUp true to show the user that selecting home will return one
485 * level up rather than to the top level of the app.
486 *
487 * @see #setDisplayOptions(int)
488 * @see #setDisplayOptions(int, int)
489 */
490 public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
491
492 /**
493 * Set whether an activity title/subtitle should be displayed.
494 *
495 * <p>To set several display options at once, see the setDisplayOptions methods.
496 *
497 * @param showTitle true to display a title/subtitle if present.
498 *
499 * @see #setDisplayOptions(int)
500 * @see #setDisplayOptions(int, int)
501 */
502 public abstract void setDisplayShowTitleEnabled(boolean showTitle);
503
504 /**
505 * Set whether a custom view should be displayed, if set.
506 *
507 * <p>To set several display options at once, see the setDisplayOptions methods.
508 *
509 * @param showCustom true if the currently set custom view should be displayed, false otherwise.
510 *
511 * @see #setDisplayOptions(int)
512 * @see #setDisplayOptions(int, int)
513 */
514 public abstract void setDisplayShowCustomEnabled(boolean showCustom);
515
Adam Powella1700782010-05-13 13:27:35 -0700516 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700517 * Set the ActionBar's background. This will be used for the primary
518 * action bar.
Adam Powell33b97432010-04-20 10:01:14 -0700519 *
520 * @param d Background drawable
Adam Powellf88b9152011-09-07 14:54:32 -0700521 * @see #setStackedBackgroundDrawable(Drawable)
522 * @see #setSplitBackgroundDrawable(Drawable)
Adam Powell33b97432010-04-20 10:01:14 -0700523 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700524 public abstract void setBackgroundDrawable(@Nullable Drawable d);
Adam Powellef704442010-11-16 14:48:22 -0800525
526 /**
Adam Powellf88b9152011-09-07 14:54:32 -0700527 * Set the ActionBar's stacked background. This will appear
528 * in the second row/stacked bar on some devices and configurations.
529 *
530 * @param d Background drawable for the stacked row
531 */
Adam Powell01453222011-09-07 16:13:36 -0700532 public void setStackedBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700533
534 /**
535 * Set the ActionBar's split background. This will appear in
536 * the split action bar containing menu-provided action buttons
537 * on some devices and configurations.
Scott Maine797ed62011-09-22 16:17:45 -0700538 * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
Adam Powellf88b9152011-09-07 14:54:32 -0700539 *
540 * @param d Background drawable for the split bar
541 */
Adam Powell01453222011-09-07 16:13:36 -0700542 public void setSplitBackgroundDrawable(Drawable d) { }
Adam Powellf88b9152011-09-07 14:54:32 -0700543
544 /**
Adam Powellef704442010-11-16 14:48:22 -0800545 * @return The current custom view.
546 */
547 public abstract View getCustomView();
548
Adam Powell33b97432010-04-20 10:01:14 -0700549 /**
Adam Powella4082912010-06-04 18:34:02 -0700550 * Returns the current ActionBar title in standard mode.
551 * Returns null if {@link #getNavigationMode()} would not return
552 * {@link #NAVIGATION_MODE_STANDARD}.
553 *
554 * @return The current ActionBar title or null.
Adam Powell33b97432010-04-20 10:01:14 -0700555 */
556 public abstract CharSequence getTitle();
557
558 /**
Adam Powella4082912010-06-04 18:34:02 -0700559 * Returns the current ActionBar subtitle in standard mode.
560 * Returns null if {@link #getNavigationMode()} would not return
561 * {@link #NAVIGATION_MODE_STANDARD}.
562 *
563 * @return The current ActionBar subtitle or null.
Adam Powell33b97432010-04-20 10:01:14 -0700564 */
565 public abstract CharSequence getSubtitle();
566
567 /**
Adam Powella4082912010-06-04 18:34:02 -0700568 * Returns the current navigation mode. The result will be one of:
569 * <ul>
570 * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
Adam Powell9ab97872010-10-26 21:47:29 -0700571 * <li>{@link #NAVIGATION_MODE_LIST}</li>
Adam Powella4082912010-06-04 18:34:02 -0700572 * <li>{@link #NAVIGATION_MODE_TABS}</li>
Adam Powella4082912010-06-04 18:34:02 -0700573 * </ul>
574 *
Adam Powell33b97432010-04-20 10:01:14 -0700575 * @return The current navigation mode.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700576 *
577 * @deprecated Action bar navigation modes are deprecated and not supported by inline
578 * toolbar action bars. Consider using other
579 * <a href="http://developer.android.com/design/patterns/navigation.html">common
580 * navigation patterns</a> instead.
Adam Powell33b97432010-04-20 10:01:14 -0700581 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700582 @NavigationMode
Adam Powell33b97432010-04-20 10:01:14 -0700583 public abstract int getNavigationMode();
Adam Powell9ab97872010-10-26 21:47:29 -0700584
585 /**
586 * Set the current navigation mode.
587 *
588 * @param mode The new mode to set.
589 * @see #NAVIGATION_MODE_STANDARD
590 * @see #NAVIGATION_MODE_LIST
591 * @see #NAVIGATION_MODE_TABS
Adam Powellfc35dfd2014-03-17 17:44:59 -0700592 *
593 * @deprecated Action bar navigation modes are deprecated and not supported by inline
594 * toolbar action bars. Consider using other
595 * <a href="http://developer.android.com/design/patterns/navigation.html">common
596 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700597 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700598 public abstract void setNavigationMode(@NavigationMode int mode);
Adam Powell9ab97872010-10-26 21:47:29 -0700599
Adam Powell33b97432010-04-20 10:01:14 -0700600 /**
601 * @return The current set of display options.
602 */
603 public abstract int getDisplayOptions();
Adam Powell661c9082010-07-02 10:09:44 -0700604
605 /**
Adam Powell661c9082010-07-02 10:09:44 -0700606 * Create and return a new {@link Tab}.
607 * This tab will not be included in the action bar until it is added.
608 *
Dianne Hackborn2f048832011-06-16 13:31:57 -0700609 * <p>Very often tabs will be used to switch between {@link Fragment}
610 * objects. Here is a typical implementation of such tabs:</p>
611 *
612 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
613 * complete}
614 *
Adam Powell661c9082010-07-02 10:09:44 -0700615 * @return A new Tab
616 *
617 * @see #addTab(Tab)
Adam Powellfc35dfd2014-03-17 17:44:59 -0700618 *
619 * @deprecated Action bar navigation modes are deprecated and not supported by inline
620 * toolbar action bars. Consider using other
621 * <a href="http://developer.android.com/design/patterns/navigation.html">common
622 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700623 */
624 public abstract Tab newTab();
625
626 /**
627 * 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 -0700628 * If this is the first tab to be added it will become the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700629 *
630 * @param tab Tab to add
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 */
637 public abstract void addTab(Tab tab);
638
639 /**
Adam Powell81b89442010-11-02 17:58:56 -0700640 * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
641 *
642 * @param tab Tab to add
643 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700644 *
645 * @deprecated Action bar navigation modes are deprecated and not supported by inline
646 * toolbar action bars. Consider using other
647 * <a href="http://developer.android.com/design/patterns/navigation.html">common
648 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700649 */
650 public abstract void addTab(Tab tab, boolean setSelected);
651
652 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700653 * Add a tab for use in tabbed navigation mode. The tab will be inserted at
Adam Powell81b89442010-11-02 17:58:56 -0700654 * <code>position</code>. If this is the first tab to be added it will become
655 * the selected tab.
Adam Powell661c9082010-07-02 10:09:44 -0700656 *
657 * @param tab The tab to add
658 * @param position The new position of the 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 Powell661c9082010-07-02 10:09:44 -0700664 */
Adam Powell2b6230e2010-09-07 17:55:25 -0700665 public abstract void addTab(Tab tab, int position);
Adam Powell661c9082010-07-02 10:09:44 -0700666
667 /**
Adam Powell81b89442010-11-02 17:58:56 -0700668 * Add a tab for use in tabbed navigation mode. The tab will be insterted at
669 * <code>position</code>.
670 *
671 * @param tab The tab to add
672 * @param position The new position of the tab
673 * @param setSelected True if the added tab should become the selected tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700674 *
675 * @deprecated Action bar navigation modes are deprecated and not supported by inline
676 * toolbar action bars. Consider using other
677 * <a href="http://developer.android.com/design/patterns/navigation.html">common
678 * navigation patterns</a> instead.
Adam Powell81b89442010-11-02 17:58:56 -0700679 */
680 public abstract void addTab(Tab tab, int position, boolean setSelected);
681
682 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700683 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
684 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700685 *
686 * @param tab The tab to remove
Adam Powellfc35dfd2014-03-17 17:44:59 -0700687 *
688 * @deprecated Action bar navigation modes are deprecated and not supported by inline
689 * toolbar action bars. Consider using other
690 * <a href="http://developer.android.com/design/patterns/navigation.html">common
691 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700692 */
693 public abstract void removeTab(Tab tab);
694
695 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700696 * Remove a tab from the action bar. If the removed tab was selected it will be deselected
697 * and another tab will be selected if present.
Adam Powell661c9082010-07-02 10:09:44 -0700698 *
699 * @param position Position of the tab to remove
Adam Powellfc35dfd2014-03-17 17:44:59 -0700700 *
701 * @deprecated Action bar navigation modes are deprecated and not supported by inline
702 * toolbar action bars. Consider using other
703 * <a href="http://developer.android.com/design/patterns/navigation.html">common
704 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700705 */
706 public abstract void removeTabAt(int position);
707
708 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700709 * Remove all tabs from the action bar and deselect the current tab.
Adam Powellfc35dfd2014-03-17 17:44:59 -0700710 *
711 * @deprecated Action bar navigation modes are deprecated and not supported by inline
712 * toolbar action bars. Consider using other
713 * <a href="http://developer.android.com/design/patterns/navigation.html">common
714 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700715 */
716 public abstract void removeAllTabs();
717
718 /**
Adam Powell661c9082010-07-02 10:09:44 -0700719 * Select the specified tab. If it is not a child of this action bar it will be added.
720 *
Adam Powell9ab97872010-10-26 21:47:29 -0700721 * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
722 *
Adam Powell661c9082010-07-02 10:09:44 -0700723 * @param tab Tab to select
Adam Powellfc35dfd2014-03-17 17:44:59 -0700724 *
725 * @deprecated Action bar navigation modes are deprecated and not supported by inline
726 * toolbar action bars. Consider using other
727 * <a href="http://developer.android.com/design/patterns/navigation.html">common
728 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -0700729 */
730 public abstract void selectTab(Tab tab);
731
732 /**
Adam Powell2b6230e2010-09-07 17:55:25 -0700733 * Returns the currently selected tab if in tabbed navigation mode and there is at least
734 * one tab present.
735 *
736 * @return The currently selected tab or null
Adam Powellfc35dfd2014-03-17 17:44:59 -0700737 *
738 * @deprecated Action bar navigation modes are deprecated and not supported by inline
739 * toolbar action bars. Consider using other
740 * <a href="http://developer.android.com/design/patterns/navigation.html">common
741 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -0700742 */
743 public abstract Tab getSelectedTab();
744
745 /**
Adam Powell9ab97872010-10-26 21:47:29 -0700746 * Returns the tab at the specified index.
747 *
748 * @param index Index value in the range 0-get
749 * @return
Adam Powellfc35dfd2014-03-17 17:44:59 -0700750 *
751 * @deprecated Action bar navigation modes are deprecated and not supported by inline
752 * toolbar action bars. Consider using other
753 * <a href="http://developer.android.com/design/patterns/navigation.html">common
754 * navigation patterns</a> instead.
Adam Powell9ab97872010-10-26 21:47:29 -0700755 */
756 public abstract Tab getTabAt(int index);
757
758 /**
Adam Powell0c24a552010-11-03 16:44:11 -0700759 * Returns the number of tabs currently registered with the action bar.
760 * @return Tab count
Adam Powellfc35dfd2014-03-17 17:44:59 -0700761 *
762 * @deprecated Action bar navigation modes are deprecated and not supported by inline
763 * toolbar action bars. Consider using other
764 * <a href="http://developer.android.com/design/patterns/navigation.html">common
765 * navigation patterns</a> instead.
Adam Powell0c24a552010-11-03 16:44:11 -0700766 */
767 public abstract int getTabCount();
768
769 /**
Adam Powell6b336f82010-08-10 20:13:01 -0700770 * Retrieve the current height of the ActionBar.
771 *
772 * @return The ActionBar's height
773 */
774 public abstract int getHeight();
775
776 /**
777 * Show the ActionBar if it is not currently showing.
778 * If the window hosting the ActionBar does not have the feature
779 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
780 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700781 *
782 * <p>If you are hiding the ActionBar through
783 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN},
784 * you should not call this function directly.
Adam Powell6b336f82010-08-10 20:13:01 -0700785 */
786 public abstract void show();
787
788 /**
Scott Maine797ed62011-09-22 16:17:45 -0700789 * Hide the ActionBar if it is currently showing.
Adam Powell6b336f82010-08-10 20:13:01 -0700790 * If the window hosting the ActionBar does not have the feature
791 * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
792 * content to fit the new space available.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700793 *
794 * <p>Instead of calling this function directly, you can also cause an
795 * ActionBar using the overlay feature to hide through
796 * {@link View#SYSTEM_UI_FLAG_FULLSCREEN View.SYSTEM_UI_FLAG_FULLSCREEN}.
797 * Hiding the ActionBar through this system UI flag allows you to more
798 * seamlessly hide it in conjunction with other screen decorations.
Adam Powell6b336f82010-08-10 20:13:01 -0700799 */
800 public abstract void hide();
801
802 /**
803 * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
804 */
805 public abstract boolean isShowing();
806
807 /**
Adam Powell8515ee82010-11-30 14:09:55 -0800808 * Add a listener that will respond to menu visibility change events.
809 *
810 * @param listener The new listener to add
Adam Powell89e06452010-06-23 20:24:52 -0700811 */
Adam Powell8515ee82010-11-30 14:09:55 -0800812 public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
813
814 /**
815 * Remove a menu visibility listener. This listener will no longer receive menu
816 * visibility change events.
817 *
818 * @param listener A listener to remove that was previously added
819 */
820 public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
821
822 /**
Adam Powellc29f4e52011-07-13 20:40:52 -0700823 * Enable or disable the "home" button in the corner of the action bar. (Note that this
824 * is the application home/up affordance on the action bar, not the systemwide home
825 * button.)
826 *
827 * <p>This defaults to true for packages targeting &lt; API 14. For packages targeting
828 * API 14 or greater, the application should call this method to enable interaction
829 * with the home/up affordance.
830 *
831 * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
832 * the home button.
833 *
834 * @param enabled true to enable the home button, false to disable the home button.
835 */
Adam Powell88ab6972011-07-28 11:25:01 -0700836 public void setHomeButtonEnabled(boolean enabled) { }
837
838 /**
839 * Returns a {@link Context} with an appropriate theme for creating views that
840 * will appear in the action bar. If you are inflating or instantiating custom views
841 * that will appear in an action bar, you should use the Context returned by this method.
842 * (This includes adapters used for list navigation mode.)
843 * This will ensure that views contrast properly against the action bar.
844 *
845 * @return A themed Context for creating views
846 */
847 public Context getThemedContext() { return null; }
Adam Powellc29f4e52011-07-13 20:40:52 -0700848
849 /**
Adam Powell27cba382013-01-22 18:55:20 -0800850 * Returns true if the Title field has been truncated during layout for lack
851 * of available space.
852 *
853 * @return true if the Title field has been truncated
854 * @hide pending API approval
855 */
856 public boolean isTitleTruncated() { return false; }
857
858 /**
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700859 * Set an alternate drawable to display next to the icon/logo/title
860 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
861 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
862 *
863 * <p>If you pass <code>null</code> to this method, the default drawable from the theme
864 * will be used.</p>
865 *
866 * <p>If you implement alternate or intermediate behavior around Up, you should also
867 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
868 * to provide a correct description of the action for accessibility support.</p>
869 *
870 * @param indicator A drawable to use for the up indicator, or null to use the theme's default
871 *
872 * @see #setDisplayOptions(int, int)
873 * @see #setDisplayHomeAsUpEnabled(boolean)
874 * @see #setHomeActionContentDescription(int)
875 */
876 public void setHomeAsUpIndicator(Drawable indicator) { }
877
878 /**
879 * Set an alternate drawable to display next to the icon/logo/title
880 * when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
881 * this mode to display an alternate selection for up navigation, such as a sliding drawer.
882 *
883 * <p>If you pass <code>0</code> to this method, the default drawable from the theme
884 * will be used.</p>
885 *
886 * <p>If you implement alternate or intermediate behavior around Up, you should also
887 * call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
888 * to provide a correct description of the action for accessibility support.</p>
889 *
890 * @param resId Resource ID of a drawable to use for the up indicator, or null
891 * to use the theme's default
892 *
893 * @see #setDisplayOptions(int, int)
894 * @see #setDisplayHomeAsUpEnabled(boolean)
895 * @see #setHomeActionContentDescription(int)
896 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700897 public void setHomeAsUpIndicator(@DrawableRes int resId) { }
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700898
899 /**
900 * Set an alternate description for the Home/Up action, when enabled.
901 *
902 * <p>This description is commonly used for accessibility/screen readers when
903 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
904 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
905 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
906 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
907 * functionality such as a sliding drawer, you should also set this to accurately
908 * describe the action.</p>
909 *
910 * <p>Setting this to <code>null</code> will use the system default description.</p>
911 *
912 * @param description New description for the Home action when enabled
913 * @see #setHomeAsUpIndicator(int)
914 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
915 */
916 public void setHomeActionContentDescription(CharSequence description) { }
917
918 /**
919 * Set an alternate description for the Home/Up action, when enabled.
920 *
921 * <p>This description is commonly used for accessibility/screen readers when
922 * the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
923 * Examples of this are, "Navigate Home" or "Navigate Up" depending on the
924 * {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
925 * indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
926 * functionality such as a sliding drawer, you should also set this to accurately
927 * describe the action.</p>
928 *
929 * <p>Setting this to <code>0</code> will use the system default description.</p>
930 *
931 * @param resId Resource ID of a string to use as the new description
932 * for the Home action when enabled
933 * @see #setHomeAsUpIndicator(int)
934 * @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
935 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700936 public void setHomeActionContentDescription(@StringRes int resId) { }
Adam Powelle0e2f4f2013-04-05 16:27:35 -0700937
Adam Powellb36e4f92014-05-01 10:23:33 -0700938 /**
939 * Enable hiding the action bar on content scroll.
940 *
941 * <p>If enabled, the action bar will scroll out of sight along with a
942 * {@link View#setNestedScrollingEnabled(boolean) nested scrolling child} view's content.
943 * The action bar must be in {@link Window#FEATURE_ACTION_BAR_OVERLAY overlay mode}
944 * to enable hiding on content scroll.</p>
945 *
946 * <p>When partially scrolled off screen the action bar is considered
947 * {@link #hide() hidden}. A call to {@link #show() show} will cause it to return to full view.
948 * </p>
949 * @param hideOnContentScroll true to enable hiding on content scroll.
950 */
951 public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
952 if (hideOnContentScroll) {
953 throw new UnsupportedOperationException("Hide on content scroll is not supported in " +
954 "this action bar configuration.");
955 }
956 }
957
958 /**
959 * Return whether the action bar is configured to scroll out of sight along with
960 * a {@link View#setNestedScrollingEnabled(boolean) nested scrolling child}.
961 *
962 * @return true if hide-on-content-scroll is enabled
963 * @see #setHideOnContentScrollEnabled(boolean)
964 */
965 public boolean isHideOnContentScrollEnabled() {
966 return false;
967 }
968
969 /**
970 * Return the current vertical offset of the action bar.
971 *
972 * <p>The action bar's current hide offset is the distance that the action bar is currently
973 * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
974 * current measured {@link #getHeight() height} (fully invisible).</p>
975 *
976 * @return The action bar's offset toward its fully hidden state in pixels
977 */
978 public int getHideOffset() {
979 return 0;
980 }
981
982 /**
983 * Set the current hide offset of the action bar.
984 *
985 * <p>The action bar's current hide offset is the distance that the action bar is currently
986 * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
987 * current measured {@link #getHeight() height} (fully invisible).</p>
988 *
989 * @param offset The action bar's offset toward its fully hidden state in pixels.
990 */
991 public void setHideOffset(int offset) {
992 if (offset != 0) {
993 throw new UnsupportedOperationException("Setting an explicit action bar hide offset " +
994 "is not supported in this action bar configuration.");
995 }
996 }
997
Adam Powell14d1fa42014-07-10 16:23:39 -0700998 /**
999 * Set the Z-axis elevation of the action bar in pixels.
1000 *
1001 * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1002 * values are closer to the user.</p>
1003 *
1004 * @param elevation Elevation value in pixels
1005 */
1006 public void setElevation(float elevation) {
1007 if (elevation != 0) {
1008 throw new UnsupportedOperationException("Setting a non-zero elevation is " +
1009 "not supported in this action bar configuration.");
1010 }
1011 }
1012
1013 /**
1014 * Get the Z-axis elevation of the action bar in pixels.
1015 *
1016 * <p>The action bar's elevation is the distance it is placed from its parent surface. Higher
1017 * values are closer to the user.</p>
1018 *
1019 * @return Elevation value in pixels
1020 */
1021 public float getElevation() {
1022 return 0;
1023 }
1024
Adam Powelle43340c2014-03-17 19:10:43 -07001025 /** @hide */
1026 public void setDefaultDisplayHomeAsUpEnabled(boolean enabled) {
1027 }
1028
1029 /** @hide */
1030 public void setShowHideAnimationEnabled(boolean enabled) {
1031 }
1032
1033 /** @hide */
1034 public void onConfigurationChanged(Configuration config) {
1035 }
1036
1037 /** @hide */
1038 public void dispatchMenuVisibilityChanged(boolean visible) {
1039 }
1040
1041 /** @hide */
Adam Powelle43340c2014-03-17 19:10:43 -07001042 public ActionMode startActionMode(ActionMode.Callback callback) {
1043 return null;
1044 }
1045
Adam Powell07a74542014-05-30 15:52:44 -07001046 /** @hide */
1047 public boolean openOptionsMenu() {
1048 return false;
1049 }
1050
1051 /** @hide */
1052 public boolean invalidateOptionsMenu() {
1053 return false;
1054 }
1055
1056 /** @hide */
1057 public boolean onMenuKeyEvent(KeyEvent event) {
1058 return false;
1059 }
1060
1061 /** @hide */
Abodunrinwa Tokia04b7ad2015-06-30 17:44:04 -07001062 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
1063 return false;
1064 }
1065
1066 /** @hide */
Adam Powell07a74542014-05-30 15:52:44 -07001067 public boolean collapseActionView() {
1068 return false;
1069 }
1070
Adam Powellaf2d8592014-08-26 18:06:40 -07001071 /** @hide */
1072 public void setWindowTitle(CharSequence title) {
1073 }
1074
Adam Powelle0e2f4f2013-04-05 16:27:35 -07001075 /**
George Mount5beb26172015-12-15 13:36:01 -08001076 * Attempts to move focus to the ActionBar if it does not already contain the focus.
1077 *
1078 * @return {@code true} if focus changes or {@code false} if focus doesn't change.
1079 * @hide
1080 */
1081 public boolean requestFocus() {
1082 return false;
1083 }
1084
Chris Banes21b25772016-01-04 20:41:59 +00001085 /** @hide */
1086 public void onDestroy() {
1087 }
1088
George Mount5beb26172015-12-15 13:36:01 -08001089 /**
1090 * Common implementation for requestFocus that takes in the Toolbar and moves focus
1091 * to the contents. This makes the ViewGroups containing the toolbar allow focus while it stays
1092 * in the ActionBar and then prevents it again once it leaves.
1093 *
1094 * @param viewGroup The toolbar ViewGroup
1095 * @return {@code true} if focus changes or {@code false} if focus doesn't change.
1096 * @hide
1097 */
1098 protected boolean requestFocus(ViewGroup viewGroup) {
1099 if (viewGroup != null && !viewGroup.hasFocus()) {
1100 final ViewGroup toolbar = viewGroup.getTouchscreenBlocksFocus() ? viewGroup : null;
1101 ViewParent parent = viewGroup.getParent();
1102 ViewGroup container = null;
1103 while (parent != null && parent instanceof ViewGroup) {
1104 final ViewGroup vgParent = (ViewGroup) parent;
1105 if (vgParent.getTouchscreenBlocksFocus()) {
1106 container = vgParent;
1107 break;
1108 }
1109 parent = vgParent.getParent();
1110 }
1111 if (container != null) {
1112 container.setTouchscreenBlocksFocus(false);
1113 }
1114 if (toolbar != null) {
1115 toolbar.setTouchscreenBlocksFocus(false);
1116 }
1117 viewGroup.requestFocus();
1118 final View focused = viewGroup.findFocus();
1119 if (focused != null) {
1120 focused.setOnFocusChangeListener(new FollowOutOfActionBar(viewGroup,
1121 container, toolbar));
1122 } else {
1123 if (container != null) {
1124 container.setTouchscreenBlocksFocus(true);
1125 }
1126 if (toolbar != null) {
1127 toolbar.setTouchscreenBlocksFocus(true);
1128 }
1129 }
1130 return true;
1131 }
1132 return false;
1133 }
1134
1135 /**
Adam Powell8515ee82010-11-30 14:09:55 -08001136 * Listener interface for ActionBar navigation events.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001137 *
1138 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1139 * toolbar action bars. Consider using other
1140 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1141 * navigation patterns</a> instead.
Adam Powell8515ee82010-11-30 14:09:55 -08001142 */
1143 public interface OnNavigationListener {
Adam Powell33b97432010-04-20 10:01:14 -07001144 /**
Adam Powella4082912010-06-04 18:34:02 -07001145 * This method is called whenever a navigation item in your action bar
1146 * is selected.
1147 *
1148 * @param itemPosition Position of the item clicked.
1149 * @param itemId ID of the item clicked.
1150 * @return True if the event was handled, false otherwise.
1151 */
1152 public boolean onNavigationItemSelected(int itemPosition, long itemId);
Adam Powell33b97432010-04-20 10:01:14 -07001153 }
Adam Powell661c9082010-07-02 10:09:44 -07001154
1155 /**
Adam Powell8515ee82010-11-30 14:09:55 -08001156 * Listener for receiving events when action bar menus are shown or hidden.
1157 */
1158 public interface OnMenuVisibilityListener {
1159 /**
1160 * Called when an action bar menu is shown or hidden. Applications may want to use
1161 * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
1162 * gameplay, or other activity within the main content area.
1163 *
1164 * @param isVisible True if an action bar menu is now visible, false if no action bar
1165 * menus are visible.
1166 */
1167 public void onMenuVisibilityChanged(boolean isVisible);
1168 }
1169
1170 /**
Adam Powell661c9082010-07-02 10:09:44 -07001171 * A tab in the action bar.
1172 *
1173 * <p>Tabs manage the hiding and showing of {@link Fragment}s.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001174 *
1175 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1176 * toolbar action bars. Consider using other
1177 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1178 * navigation patterns</a> instead.
Adam Powell661c9082010-07-02 10:09:44 -07001179 */
1180 public static abstract class Tab {
1181 /**
1182 * An invalid position for a tab.
1183 *
1184 * @see #getPosition()
1185 */
1186 public static final int INVALID_POSITION = -1;
1187
1188 /**
1189 * Return the current position of this tab in the action bar.
1190 *
1191 * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
1192 * the action bar.
1193 */
1194 public abstract int getPosition();
1195
1196 /**
1197 * Return the icon associated with this tab.
1198 *
1199 * @return The tab's icon
1200 */
1201 public abstract Drawable getIcon();
1202
1203 /**
1204 * Return the text of this tab.
1205 *
1206 * @return The tab's text
1207 */
1208 public abstract CharSequence getText();
1209
1210 /**
1211 * Set the icon displayed on this tab.
1212 *
1213 * @param icon The drawable to use as an icon
Adam Powell9ab97872010-10-26 21:47:29 -07001214 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001215 */
Adam Powell9ab97872010-10-26 21:47:29 -07001216 public abstract Tab setIcon(Drawable icon);
Adam Powell661c9082010-07-02 10:09:44 -07001217
1218 /**
Adam Powell32555f32010-11-17 13:49:22 -08001219 * Set the icon displayed on this tab.
1220 *
1221 * @param resId Resource ID referring to the drawable to use as an icon
1222 * @return The current instance for call chaining
1223 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001224 public abstract Tab setIcon(@DrawableRes int resId);
Adam Powell32555f32010-11-17 13:49:22 -08001225
1226 /**
Adam Powell661c9082010-07-02 10:09:44 -07001227 * Set the text displayed on this tab. Text may be truncated if there is not
1228 * room to display the entire string.
1229 *
1230 * @param text The text to display
Adam Powell9ab97872010-10-26 21:47:29 -07001231 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001232 */
Adam Powell9ab97872010-10-26 21:47:29 -07001233 public abstract Tab setText(CharSequence text);
Adam Powell661c9082010-07-02 10:09:44 -07001234
1235 /**
Adam Powell32555f32010-11-17 13:49:22 -08001236 * Set the text displayed on this tab. Text may be truncated if there is not
1237 * room to display the entire string.
1238 *
1239 * @param resId A resource ID referring to the text that should be displayed
1240 * @return The current instance for call chaining
1241 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001242 public abstract Tab setText(@StringRes int resId);
Adam Powell32555f32010-11-17 13:49:22 -08001243
1244 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001245 * Set a custom view to be used for this tab. This overrides values set by
1246 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
Adam Powell661c9082010-07-02 10:09:44 -07001247 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001248 * @param view Custom view to be used as a tab.
Adam Powell9ab97872010-10-26 21:47:29 -07001249 * @return The current instance for call chaining
Adam Powell661c9082010-07-02 10:09:44 -07001250 */
Adam Powell9ab97872010-10-26 21:47:29 -07001251 public abstract Tab setCustomView(View view);
Adam Powell661c9082010-07-02 10:09:44 -07001252
1253 /**
Adam Powell32555f32010-11-17 13:49:22 -08001254 * Set a custom view to be used for this tab. This overrides values set by
1255 * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
1256 *
1257 * @param layoutResId A layout resource to inflate and use as a custom tab view
1258 * @return The current instance for call chaining
1259 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001260 public abstract Tab setCustomView(@LayoutRes int layoutResId);
Adam Powell32555f32010-11-17 13:49:22 -08001261
1262 /**
Adam Powell2b6230e2010-09-07 17:55:25 -07001263 * Retrieve a previously set custom view for this tab.
Adam Powell661c9082010-07-02 10:09:44 -07001264 *
Adam Powell2b6230e2010-09-07 17:55:25 -07001265 * @return The custom view set by {@link #setCustomView(View)}.
Adam Powell661c9082010-07-02 10:09:44 -07001266 */
Adam Powell2b6230e2010-09-07 17:55:25 -07001267 public abstract View getCustomView();
1268
1269 /**
1270 * Give this Tab an arbitrary object to hold for later use.
1271 *
1272 * @param obj Object to store
Adam Powell9ab97872010-10-26 21:47:29 -07001273 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001274 */
Adam Powell9ab97872010-10-26 21:47:29 -07001275 public abstract Tab setTag(Object obj);
Adam Powell2b6230e2010-09-07 17:55:25 -07001276
1277 /**
1278 * @return This Tab's tag object.
1279 */
1280 public abstract Object getTag();
1281
1282 /**
1283 * Set the {@link TabListener} that will handle switching to and from this tab.
1284 * All tabs must have a TabListener set before being added to the ActionBar.
1285 *
1286 * @param listener Listener to handle tab selection events
Adam Powell9ab97872010-10-26 21:47:29 -07001287 * @return The current instance for call chaining
Adam Powell2b6230e2010-09-07 17:55:25 -07001288 */
Adam Powell9ab97872010-10-26 21:47:29 -07001289 public abstract Tab setTabListener(TabListener listener);
Adam Powell661c9082010-07-02 10:09:44 -07001290
1291 /**
1292 * Select this tab. Only valid if the tab has been added to the action bar.
1293 */
1294 public abstract void select();
Adam Powell94e56ef2011-09-06 21:22:22 -07001295
1296 /**
1297 * Set a description of this tab's content for use in accessibility support.
1298 * If no content description is provided the title will be used.
1299 *
1300 * @param resId A resource ID referring to the description text
1301 * @return The current instance for call chaining
1302 * @see #setContentDescription(CharSequence)
1303 * @see #getContentDescription()
1304 */
Tor Norbye7b9c9122013-05-30 16:48:33 -07001305 public abstract Tab setContentDescription(@StringRes int resId);
Adam Powell94e56ef2011-09-06 21:22:22 -07001306
1307 /**
1308 * Set a description of this tab's content for use in accessibility support.
1309 * If no content description is provided the title will be used.
1310 *
1311 * @param contentDesc Description of this tab's content
1312 * @return The current instance for call chaining
1313 * @see #setContentDescription(int)
1314 * @see #getContentDescription()
1315 */
1316 public abstract Tab setContentDescription(CharSequence contentDesc);
1317
1318 /**
1319 * Gets a brief description of this tab's content for use in accessibility support.
1320 *
1321 * @return Description of this tab's content
1322 * @see #setContentDescription(CharSequence)
1323 * @see #setContentDescription(int)
1324 */
1325 public abstract CharSequence getContentDescription();
Adam Powell661c9082010-07-02 10:09:44 -07001326 }
Adam Powell2b6230e2010-09-07 17:55:25 -07001327
1328 /**
1329 * Callback interface invoked when a tab is focused, unfocused, added, or removed.
Adam Powellfc35dfd2014-03-17 17:44:59 -07001330 *
1331 * @deprecated Action bar navigation modes are deprecated and not supported by inline
1332 * toolbar action bars. Consider using other
1333 * <a href="http://developer.android.com/design/patterns/navigation.html">common
1334 * navigation patterns</a> instead.
Adam Powell2b6230e2010-09-07 17:55:25 -07001335 */
1336 public interface TabListener {
1337 /**
1338 * Called when a tab enters the selected state.
1339 *
1340 * @param tab The tab that was selected
1341 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1342 * during a tab switch. The previous tab's unselect and this tab's select will be
Adam Powell0c24a552010-11-03 16:44:11 -07001343 * executed in a single transaction. This FragmentTransaction does not support
1344 * being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001345 */
1346 public void onTabSelected(Tab tab, FragmentTransaction ft);
1347
1348 /**
1349 * Called when a tab exits the selected state.
1350 *
1351 * @param tab The tab that was unselected
1352 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
1353 * during a tab switch. This tab's unselect and the newly selected tab's select
Adam Powell0c24a552010-11-03 16:44:11 -07001354 * will be executed in a single transaction. This FragmentTransaction does not
1355 * support being added to the back stack.
Adam Powell2b6230e2010-09-07 17:55:25 -07001356 */
1357 public void onTabUnselected(Tab tab, FragmentTransaction ft);
Adam Powell7f9b9052010-10-19 16:56:07 -07001358
1359 /**
1360 * Called when a tab that is already selected is chosen again by the user.
1361 * Some applications may use this action to return to the top level of a category.
1362 *
1363 * @param tab The tab that was reselected.
1364 * @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
Adam Powell0c24a552010-11-03 16:44:11 -07001365 * once this method returns. This FragmentTransaction does not support
1366 * being added to the back stack.
Adam Powell7f9b9052010-10-19 16:56:07 -07001367 */
1368 public void onTabReselected(Tab tab, FragmentTransaction ft);
Adam Powell2b6230e2010-09-07 17:55:25 -07001369 }
Adam Powell9ab97872010-10-26 21:47:29 -07001370
1371 /**
1372 * Per-child layout information associated with action bar custom views.
1373 *
1374 * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
1375 */
Adam Powelle43340c2014-03-17 19:10:43 -07001376 public static class LayoutParams extends ViewGroup.MarginLayoutParams {
Adam Powell9ab97872010-10-26 21:47:29 -07001377 /**
1378 * Gravity for the view associated with these LayoutParams.
1379 *
1380 * @see android.view.Gravity
1381 */
1382 @ViewDebug.ExportedProperty(category = "layout", mapping = {
Adam Powelle43340c2014-03-17 19:10:43 -07001383 @ViewDebug.IntToString(from = -1, to = "NONE"),
1384 @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"),
1385 @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
1386 @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
1387 @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"),
1388 @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"),
1389 @ViewDebug.IntToString(from = Gravity.START, to = "START"),
1390 @ViewDebug.IntToString(from = Gravity.END, to = "END"),
1391 @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"),
1392 @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"),
1393 @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
1394 @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"),
1395 @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
1396 @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
Adam Powell9ab97872010-10-26 21:47:29 -07001397 })
Fabrice Di Megliocf1ba022012-06-25 15:49:11 -07001398 public int gravity = Gravity.NO_GRAVITY;
Adam Powell9ab97872010-10-26 21:47:29 -07001399
Tor Norbyed9273d62013-05-30 15:59:53 -07001400 public LayoutParams(@NonNull Context c, AttributeSet attrs) {
Adam Powell9ab97872010-10-26 21:47:29 -07001401 super(c, attrs);
Adam Powellb226bea2014-04-04 12:23:42 -07001402
1403 TypedArray a = c.obtainStyledAttributes(attrs,
1404 com.android.internal.R.styleable.ActionBar_LayoutParams);
1405 gravity = a.getInt(
1406 com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity,
1407 Gravity.NO_GRAVITY);
1408 a.recycle();
Adam Powell9ab97872010-10-26 21:47:29 -07001409 }
1410
1411 public LayoutParams(int width, int height) {
1412 super(width, height);
Adam Powelle021e6e2014-05-23 17:27:24 -07001413 this.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
Adam Powell9ab97872010-10-26 21:47:29 -07001414 }
1415
1416 public LayoutParams(int width, int height, int gravity) {
1417 super(width, height);
Alan Viveretteda4bd6f2014-04-14 12:58:34 -07001418
1419 this.gravity = gravity;
Adam Powell9ab97872010-10-26 21:47:29 -07001420 }
1421
1422 public LayoutParams(int gravity) {
1423 this(WRAP_CONTENT, MATCH_PARENT, gravity);
1424 }
1425
1426 public LayoutParams(LayoutParams source) {
1427 super(source);
Adam Powelle021e6e2014-05-23 17:27:24 -07001428 this.gravity = source.gravity;
Adam Powell9ab97872010-10-26 21:47:29 -07001429 }
1430
1431 public LayoutParams(ViewGroup.LayoutParams source) {
1432 super(source);
1433 }
Adam Powelle43340c2014-03-17 19:10:43 -07001434
Adam Powelld7600832014-07-01 15:22:50 -07001435 /*
1436 * Note for framework developers:
1437 *
1438 * You might notice that ActionBar.LayoutParams is missing a constructor overload
1439 * for MarginLayoutParams. While it may seem like a good idea to add one, at this
1440 * point it's dangerous for source compatibility. Upon building against a new
1441 * version of the SDK an app can end up statically linking to the new MarginLayoutParams
1442 * overload, causing a crash when running on older platform versions with no other changes.
1443 */
Siva Velusamy94a6d152015-05-05 15:07:00 -07001444
1445 /** @hide */
1446 @Override
1447 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
1448 super.encodeProperties(encoder);
1449
1450 encoder.addProperty("gravity", gravity);
1451 }
Adam Powell9ab97872010-10-26 21:47:29 -07001452 }
George Mount5beb26172015-12-15 13:36:01 -08001453
1454 /**
1455 * Tracks the focused View until it leaves the ActionBar, then it resets the
1456 * touchscreenBlocksFocus value.
1457 */
1458 private static class FollowOutOfActionBar implements OnFocusChangeListener, Runnable {
1459 private final ViewGroup mFocusRoot;
1460 private final ViewGroup mContainer;
1461 private final ViewGroup mToolbar;
1462
1463 public FollowOutOfActionBar(ViewGroup focusRoot, ViewGroup container, ViewGroup toolbar) {
1464 mContainer = container;
1465 mToolbar = toolbar;
1466 mFocusRoot = focusRoot;
1467 }
1468
1469 @Override
1470 public void onFocusChange(View v, boolean hasFocus) {
1471 if (!hasFocus) {
1472 v.setOnFocusChangeListener(null);
1473 final View focused = mFocusRoot.findFocus();
1474 if (focused != null) {
1475 focused.setOnFocusChangeListener(this);
1476 } else {
1477 mFocusRoot.post(this);
1478 }
1479 }
1480 }
1481
1482 @Override
1483 public void run() {
1484 if (mContainer != null) {
1485 mContainer.setTouchscreenBlocksFocus(true);
1486 }
1487 if (mToolbar != null) {
1488 mToolbar.setTouchscreenBlocksFocus(true);
1489 }
1490 }
1491 }
Adam Powell33b97432010-04-20 10:01:14 -07001492}