public class

WindowDecorActionBar

extends ActionBar

implements ActionBarOverlayLayout.ActionBarVisibilityCallback

 java.lang.Object

androidx.appcompat.app.ActionBar

↳androidx.appcompat.app.WindowDecorActionBar

Gradle dependencies

compile group: 'androidx.appcompat', name: 'appcompat', version: '1.6.0-alpha04'

  • groupId: androidx.appcompat
  • artifactId: appcompat
  • version: 1.6.0-alpha04

Artifact androidx.appcompat:appcompat:1.6.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.appcompat:appcompat com.android.support:appcompat-v7

Androidx class mapping:

androidx.appcompat.app.WindowDecorActionBar android.support.v7.app.WindowDecorActionBar

Overview

WindowDecorActionBar is the ActionBar implementation used by devices of all screen sizes as part of the window decor layout.

Summary

Fields
from ActionBarDISPLAY_HOME_AS_UP, DISPLAY_SHOW_CUSTOM, DISPLAY_SHOW_HOME, DISPLAY_SHOW_TITLE, DISPLAY_USE_LOGO, NAVIGATION_MODE_LIST, NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_TABS
Constructors
publicWindowDecorActionBar(Activity activity, boolean overlayMode)

publicWindowDecorActionBar(Dialog dialog)

publicWindowDecorActionBar(View layout)

Only for edit mode.

Methods
public abstract voidaddOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)

Add a listener that will respond to menu visibility change events.

public abstract voidaddTab(ActionBar.Tab tab)

Add a tab for use in tabbed navigation mode.

public abstract voidaddTab(ActionBar.Tab tab, boolean setSelected)

Add a tab for use in tabbed navigation mode.

public abstract voidaddTab(ActionBar.Tab tab, int position)

Add a tab for use in tabbed navigation mode.

public abstract voidaddTab(ActionBar.Tab tab, int position, boolean setSelected)

Add a tab for use in tabbed navigation mode.

public voidanimateToMode(boolean toActionMode)

public booleancollapseActionView()

public voiddispatchMenuVisibilityChanged(boolean visible)

public voiddoHide(boolean fromSystem)

public voiddoShow(boolean fromSystem)

public voidenableContentAnimations(boolean enabled)

public abstract ViewgetCustomView()

public abstract intgetDisplayOptions()

public floatgetElevation()

Get the Z-axis elevation of the action bar in pixels.

public abstract intgetHeight()

Retrieve the current height of the ActionBar.

public intgetHideOffset()

Return the current vertical offset of the action bar.

public abstract intgetNavigationItemCount()

Get the number of navigation items present in the current navigation mode.

public abstract intgetNavigationMode()

Returns the current navigation mode.

public abstract intgetSelectedNavigationIndex()

Get the position of the selected navigation item in list or tabbed navigation modes.

public abstract ActionBar.TabgetSelectedTab()

Returns the currently selected tab if in tabbed navigation mode and there is at least one tab present.

public abstract java.lang.CharSequencegetSubtitle()

Returns the current ActionBar subtitle in standard mode.

public abstract ActionBar.TabgetTabAt(int index)

Returns the tab at the specified index.

public abstract intgetTabCount()

Returns the number of tabs currently registered with the action bar.

public ContextgetThemedContext()

Returns a with an appropriate theme for creating views that will appear in the action bar.

public abstract java.lang.CharSequencegetTitle()

Returns the current ActionBar title in standard mode.

public booleanhasIcon()

public booleanhasLogo()

public abstract voidhide()

Hide the ActionBar if it is currently showing.

public voidhideForSystem()

public booleanisHideOnContentScrollEnabled()

Return whether the action bar is configured to scroll out of sight along with a nested scrolling child.

public abstract booleanisShowing()

public booleanisTitleTruncated()

Returns true if the Title field has been truncated during layout for lack of available space.

public abstract ActionBar.TabnewTab()

Create and return a new ActionBar.Tab.

public voidonConfigurationChanged(Configuration config)

public voidonContentScrollStarted()

public voidonContentScrollStopped()

public booleanonKeyShortcut(int keyCode, KeyEvent ev)

public voidonWindowVisibilityChanged(int visibility)

public abstract voidremoveAllTabs()

Remove all tabs from the action bar and deselect the current tab.

public abstract voidremoveOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)

Remove a menu visibility listener.

public abstract voidremoveTab(ActionBar.Tab tab)

Remove a tab from the action bar.

public abstract voidremoveTabAt(int position)

Remove a tab from the action bar.

booleanrequestFocus()

Attempts to move focus to the ActionBar if it does not already contain the focus.

public abstract voidselectTab(ActionBar.Tab tab)

Select the specified tab.

public abstract voidsetBackgroundDrawable(Drawable d)

Set the ActionBar's background.

public abstract voidsetCustomView(View view)

Set the action bar into custom navigation mode, supplying a view for custom navigation.

public abstract voidsetCustomView(View view)

Set the action bar into custom navigation mode, supplying a view for custom navigation.

public abstract voidsetCustomView(View view, ActionBar.LayoutParams layoutParams)

Set the action bar into custom navigation mode, supplying a view for custom navigation.

public voidsetDefaultDisplayHomeAsUpEnabled(boolean enabled)

public abstract voidsetDisplayHomeAsUpEnabled(boolean showHomeAsUp)

Set whether home should be displayed as an "up" affordance.

public abstract voidsetDisplayOptions(int options)

Set display options.

public abstract voidsetDisplayOptions(int options, int mask)

Set selected display options.

public abstract voidsetDisplayShowCustomEnabled(boolean showCustom)

Set whether a custom view should be displayed, if set.

public abstract voidsetDisplayShowHomeEnabled(boolean showHome)

Set whether to include the application home affordance in the action bar.

public abstract voidsetDisplayShowTitleEnabled(boolean showTitle)

Set whether an activity title/subtitle should be displayed.

public abstract voidsetDisplayUseLogoEnabled(boolean useLogo)

Set whether to display the activity logo rather than the activity icon.

public voidsetElevation(float elevation)

Set the Z-axis elevation of the action bar in pixels.

public voidsetHideOffset(int offset)

Set the current hide offset of the action bar.

public voidsetHideOnContentScrollEnabled(boolean hideOnContentScroll)

Enable hiding the action bar on content scroll.

public voidsetHomeActionContentDescription(java.lang.CharSequence description)

Set an alternate description for the Home/Up action, when enabled.

public voidsetHomeActionContentDescription(int resId)

Set an alternate description for the Home/Up action, when enabled.

public voidsetHomeAsUpIndicator(Drawable indicator)

Set an alternate drawable to display next to the icon/logo/title when ActionBar.DISPLAY_HOME_AS_UP is enabled.

public voidsetHomeButtonEnabled(boolean enabled)

Enable or disable the "home" button in the corner of the action bar.

public abstract voidsetIcon(Drawable icon)

Set the icon to display in the 'home' section of the action bar.

public abstract voidsetIcon(Drawable icon)

Set the icon to display in the 'home' section of the action bar.

public abstract voidsetListNavigationCallbacks(SpinnerAdapter adapter, ActionBar.OnNavigationListener callback)

Set the adapter and navigation callback for list navigation mode.

public abstract voidsetLogo(Drawable logo)

Set the logo to display in the 'home' section of the action bar.

public abstract voidsetLogo(Drawable logo)

Set the logo to display in the 'home' section of the action bar.

public abstract voidsetNavigationMode(int mode)

Set the current navigation mode.

public abstract voidsetSelectedNavigationItem(int position)

Set the selected navigation item in list or tabbed navigation modes.

public voidsetShowHideAnimationEnabled(boolean enabled)

Enables or disables animation between show/hide states.

public voidsetSplitBackgroundDrawable(Drawable d)

Set the ActionBar's split background.

public voidsetStackedBackgroundDrawable(Drawable d)

Set the ActionBar's stacked background.

public abstract voidsetSubtitle(java.lang.CharSequence subtitle)

Set the action bar's subtitle.

public abstract voidsetSubtitle(int resId)

Set the action bar's subtitle.

public abstract voidsetTitle(java.lang.CharSequence title)

Set the action bar's title.

public abstract voidsetTitle(int resId)

Set the action bar's title.

public voidsetWindowTitle(java.lang.CharSequence title)

public abstract voidshow()

Show the ActionBar if it is not currently showing.

public voidshowForSystem()

public ActionModestartActionMode(ActionMode.Callback callback)

from ActionBarcloseOptionsMenu, invalidateOptionsMenu, onMenuKeyEvent, openOptionsMenu, setIcon, setLogo
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public WindowDecorActionBar(Activity activity, boolean overlayMode)

public WindowDecorActionBar(Dialog dialog)

public WindowDecorActionBar(View layout)

Only for edit mode.

Methods

public void setElevation(float elevation)

Set the Z-axis elevation of the action bar in pixels.

The action bar's elevation is the distance it is placed from its parent surface. Higher values are closer to the user.

Parameters:

elevation: Elevation value in pixels

public float getElevation()

Get the Z-axis elevation of the action bar in pixels.

The action bar's elevation is the distance it is placed from its parent surface. Higher values are closer to the user.

Returns:

Elevation value in pixels

public void onConfigurationChanged(Configuration config)

public void onWindowVisibilityChanged(int visibility)

public void setShowHideAnimationEnabled(boolean enabled)

Enables or disables animation between show/hide states. If animation is disabled using this method, animations in progress will be finished.

Parameters:

enabled: true to animate, false to not animate.

public abstract void addOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)

Add a listener that will respond to menu visibility change events.

Parameters:

listener: The new listener to add

public abstract void removeOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)

Remove a menu visibility listener. This listener will no longer receive menu visibility change events.

Parameters:

listener: A listener to remove that was previously added

public void dispatchMenuVisibilityChanged(boolean visible)

public abstract void setCustomView(View view)

Set the action bar into custom navigation mode, supplying a view for custom navigation. Custom navigation views appear between the application icon and any action buttons and may use any space available there. Common use cases for custom navigation views might include an auto-suggesting address bar for a browser or other navigation mechanisms that do not translate well to provided navigation modes.

Parameters:

view: Custom navigation view to place in the ActionBar.

public abstract void setDisplayUseLogoEnabled(boolean useLogo)

Set whether to display the activity logo rather than the activity icon. A logo is often a wider, more detailed image.

To set several display options at once, see the setDisplayOptions methods.

Parameters:

useLogo: true to use the activity logo, false to use the activity icon.

See also: ActionBar.setDisplayOptions(int), ActionBar.setDisplayOptions(int, int)

public abstract void setDisplayShowHomeEnabled(boolean showHome)

Set whether to include the application home affordance in the action bar. Home is presented as either an activity icon or logo.

To set several display options at once, see the setDisplayOptions methods.

Parameters:

showHome: true to show home, false otherwise.

See also: ActionBar.setDisplayOptions(int), ActionBar.setDisplayOptions(int, int)

public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp)

Set whether home should be displayed as an "up" affordance. Set this to true if selecting "home" returns up by a single level in your UI rather than back to the top level or front page.

To set several display options at once, see the setDisplayOptions methods.

Parameters:

showHomeAsUp: true to show the user that selecting home will return one level up rather than to the top level of the app.

See also: ActionBar.setDisplayOptions(int), ActionBar.setDisplayOptions(int, int)

public abstract void setDisplayShowTitleEnabled(boolean showTitle)

Set whether an activity title/subtitle should be displayed.

To set several display options at once, see the setDisplayOptions methods.

Parameters:

showTitle: true to display a title/subtitle if present.

See also: ActionBar.setDisplayOptions(int), ActionBar.setDisplayOptions(int, int)

public abstract void setDisplayShowCustomEnabled(boolean showCustom)

Set whether a custom view should be displayed, if set.

To set several display options at once, see the setDisplayOptions methods.

Parameters:

showCustom: true if the currently set custom view should be displayed, false otherwise.

See also: ActionBar.setDisplayOptions(int), ActionBar.setDisplayOptions(int, int)

public void setHomeButtonEnabled(boolean enabled)

Enable or disable the "home" button in the corner of the action bar. (Note that this is the application home/up affordance on the action bar, not the system wide home button.)

This defaults to true for packages targeting < API 14. For packages targeting API 14 or greater, the application should call this method to enable interaction with the home/up affordance.

Setting the ActionBar.DISPLAY_HOME_AS_UP display option will automatically enable the home button.

Parameters:

enabled: true to enable the home button, false to disable the home button.

public abstract void setTitle(int resId)

Set the action bar's title. This will only be displayed if ActionBar.DISPLAY_SHOW_TITLE is set.

Parameters:

resId: Resource ID of title string to set

See also: ActionBar.setTitle(CharSequence), ActionBar.setDisplayOptions(int, int)

public abstract void setSubtitle(int resId)

Set the action bar's subtitle. This will only be displayed if ActionBar.DISPLAY_SHOW_TITLE is set.

Parameters:

resId: Resource ID of subtitle string to set

See also: ActionBar.setSubtitle(CharSequence), ActionBar.setDisplayOptions(int, int)

public abstract void setSelectedNavigationItem(int position)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Set the selected navigation item in list or tabbed navigation modes.

Parameters:

position: Position of the item to select.

public abstract void removeAllTabs()

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Remove all tabs from the action bar and deselect the current tab.

public abstract void setTitle(java.lang.CharSequence title)

Set the action bar's title. This will only be displayed if ActionBar.DISPLAY_SHOW_TITLE is set.

Parameters:

title: Title to set

See also: ActionBar.setTitle(int), ActionBar.setDisplayOptions(int, int)

public void setWindowTitle(java.lang.CharSequence title)

boolean requestFocus()

Attempts to move focus to the ActionBar if it does not already contain the focus.

Returns:

true if focus changes or false if focus doesn't change.

public abstract void setSubtitle(java.lang.CharSequence subtitle)

Set the action bar's subtitle. This will only be displayed if ActionBar.DISPLAY_SHOW_TITLE is set. Set to null to disable the subtitle entirely.

Parameters:

subtitle: Subtitle to set

See also: ActionBar.setSubtitle(int), ActionBar.setDisplayOptions(int, int)

public abstract void setDisplayOptions(int options)

Set display options. This changes all display option bits at once. To change a limited subset of display options, see ActionBar.setDisplayOptions(int, int).

Parameters:

options: A combination of the bits defined by the DISPLAY_ constants defined in ActionBar.

public abstract void setDisplayOptions(int options, int mask)

Set selected display options. Only the options specified by mask will be changed. To change all display option bits at once, see ActionBar.setDisplayOptions(int).

Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the ActionBar.DISPLAY_SHOW_HOME option. setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO) will enable ActionBar.DISPLAY_SHOW_HOME and disable ActionBar.DISPLAY_USE_LOGO.

Parameters:

options: A combination of the bits defined by the DISPLAY_ constants defined in ActionBar.
mask: A bit mask declaring which display options should be changed.

public abstract void setBackgroundDrawable(Drawable d)

Set the ActionBar's background. This will be used for the primary action bar.

Parameters:

d: Background drawable

See also: ActionBar.setStackedBackgroundDrawable(Drawable), ActionBar.setSplitBackgroundDrawable(Drawable)

public void setStackedBackgroundDrawable(Drawable d)

Set the ActionBar's stacked background. This will appear in the second row/stacked bar on some devices and configurations.

Parameters:

d: Background drawable for the stacked row

public void setSplitBackgroundDrawable(Drawable d)

Set the ActionBar's split background. This will appear in the split action bar containing menu-provided action buttons on some devices and configurations.

You can enable split action bar with

Parameters:

d: Background drawable for the split bar

public abstract View getCustomView()

Returns:

The current custom view.

public abstract java.lang.CharSequence getTitle()

Returns the current ActionBar title in standard mode. Returns null if ActionBar.getNavigationMode() would not return ActionBar.NAVIGATION_MODE_STANDARD.

Returns:

The current ActionBar title or null.

public abstract java.lang.CharSequence getSubtitle()

Returns the current ActionBar subtitle in standard mode. Returns null if ActionBar.getNavigationMode() would not return ActionBar.NAVIGATION_MODE_STANDARD.

Returns:

The current ActionBar subtitle or null.

public abstract int getNavigationMode()

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Returns the current navigation mode. The result will be one of:

Returns:

The current navigation mode.

public abstract int getDisplayOptions()

Returns:

The current set of display options.

public ActionMode startActionMode(ActionMode.Callback callback)

public abstract void addTab(ActionBar.Tab tab)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list. If this is the first tab to be added it will become the selected tab.

Parameters:

tab: Tab to add

public abstract void addTab(ActionBar.Tab tab, int position)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Add a tab for use in tabbed navigation mode. The tab will be inserted at position. If this is the first tab to be added it will become the selected tab.

Parameters:

tab: The tab to add
position: The new position of the tab

public abstract void addTab(ActionBar.Tab tab, boolean setSelected)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.

Parameters:

tab: Tab to add
setSelected: True if the added tab should become the selected tab.

public abstract void addTab(ActionBar.Tab tab, int position, boolean setSelected)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Add a tab for use in tabbed navigation mode. The tab will be inserted at position.

Parameters:

tab: The tab to add
position: The new position of the tab
setSelected: True if the added tab should become the selected tab.

public abstract ActionBar.Tab newTab()

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Create and return a new ActionBar.Tab. This tab will not be included in the action bar until it is added.

Returns:

A new Tab

See also: ActionBar.addTab(ActionBar.Tab)

public abstract void removeTab(ActionBar.Tab tab)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Remove a tab from the action bar. If the removed tab was selected it will be deselected and another tab will be selected if present.

Parameters:

tab: The tab to remove

public abstract void removeTabAt(int position)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Remove a tab from the action bar. If the removed tab was selected it will be deselected and another tab will be selected if present.

Parameters:

position: Position of the tab to remove

public abstract void selectTab(ActionBar.Tab tab)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Select the specified tab. If it is not a child of this action bar it will be added.

Note: If you want to select by index, use ActionBar.setSelectedNavigationItem(int).

Parameters:

tab: Tab to select

public abstract ActionBar.Tab getSelectedTab()

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Returns the currently selected tab if in tabbed navigation mode and there is at least one tab present.

Returns:

The currently selected tab or null

public abstract int getHeight()

Retrieve the current height of the ActionBar.

Returns:

The ActionBar's height

public void enableContentAnimations(boolean enabled)

public abstract void show()

Show the ActionBar if it is not currently showing. If the window hosting the ActionBar does not have the feature Window it will resize application content to fit the new space available.

If you are hiding the ActionBar through View.SYSTEM_UI_FLAG_FULLSCREEN, you should not call this function directly.

public void showForSystem()

public abstract void hide()

Hide the ActionBar if it is currently showing. If the window hosting the ActionBar does not have the feature Window it will resize application content to fit the new space available.

Instead of calling this function directly, you can also cause an ActionBar using the overlay feature to hide through View.SYSTEM_UI_FLAG_FULLSCREEN. Hiding the ActionBar through this system UI flag allows you to more seamlessly hide it in conjunction with other screen decorations.

public void hideForSystem()

public void setHideOnContentScrollEnabled(boolean hideOnContentScroll)

Enable hiding the action bar on content scroll.

If enabled, the action bar will scroll out of sight along with a nested scrolling child view's content. The action bar must be in overlay mode to enable hiding on content scroll.

When partially scrolled off screen the action bar is considered hidden. A call to show will cause it to return to full view.

Parameters:

hideOnContentScroll: true to enable hiding on content scroll.

public boolean isHideOnContentScrollEnabled()

Return whether the action bar is configured to scroll out of sight along with a nested scrolling child.

Returns:

true if hide-on-content-scroll is enabled

See also: ActionBar.setHideOnContentScrollEnabled(boolean)

public int getHideOffset()

Return the current vertical offset of the action bar.

The action bar's current hide offset is the distance that the action bar is currently scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's current measured height (fully invisible).

Returns:

The action bar's offset toward its fully hidden state in pixels

public void setHideOffset(int offset)

Set the current hide offset of the action bar.

The action bar's current hide offset is the distance that the action bar is currently scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's current measured height (fully invisible).

Parameters:

offset: The action bar's offset toward its fully hidden state in pixels.

public void doShow(boolean fromSystem)

public void doHide(boolean fromSystem)

public abstract boolean isShowing()

Returns:

true if the ActionBar is showing, false otherwise.

public void animateToMode(boolean toActionMode)

public Context getThemedContext()

Returns a with an appropriate theme for creating views that will appear in the action bar. If you are inflating or instantiating custom views that will appear in an action bar, you should use the Context returned by this method. (This includes adapters used for list navigation mode.) This will ensure that views contrast properly against the action bar.

Returns:

A themed Context for creating views

public boolean isTitleTruncated()

Returns true if the Title field has been truncated during layout for lack of available space.

Returns:

true if the Title field has been truncated

public void setHomeAsUpIndicator(Drawable indicator)

Set an alternate drawable to display next to the icon/logo/title when ActionBar.DISPLAY_HOME_AS_UP is enabled. This can be useful if you are using this mode to display an alternate selection for up navigation, such as a sliding drawer.

If you pass null to this method, the default drawable from the theme will be used.

If you implement alternate or intermediate behavior around Up, you should also call setHomeActionContentDescription() to provide a correct description of the action for accessibility support.

Parameters:

indicator: A drawable to use for the up indicator, or null to use the theme's default

See also: ActionBar.setDisplayOptions(int, int), ActionBar.setDisplayHomeAsUpEnabled(boolean), ActionBar.setHomeActionContentDescription(int)

public void setHomeActionContentDescription(java.lang.CharSequence description)

Set an alternate description for the Home/Up action, when enabled.

This description is commonly used for accessibility/screen readers when the Home action is enabled. (See ActionBar.setDisplayHomeAsUpEnabled(boolean).) Examples of this are, "Navigate Home" or "Navigate Up" depending on the ActionBar.DISPLAY_HOME_AS_UP display option. If you have changed the home-as-up indicator using ActionBar to indicate more specific functionality such as a sliding drawer, you should also set this to accurately describe the action.

Setting this to null will use the system default description.

Parameters:

description: New description for the Home action when enabled

See also: ActionBar, ActionBar

public void setHomeActionContentDescription(int resId)

Set an alternate description for the Home/Up action, when enabled.

This description is commonly used for accessibility/screen readers when the Home action is enabled. (See ActionBar.setDisplayHomeAsUpEnabled(boolean).) Examples of this are, "Navigate Home" or "Navigate Up" depending on the ActionBar.DISPLAY_HOME_AS_UP display option. If you have changed the home-as-up indicator using ActionBar to indicate more specific functionality such as a sliding drawer, you should also set this to accurately describe the action.

Setting this to 0 will use the system default description.

Parameters:

resId: Resource ID of a string to use as the new description for the Home action when enabled

See also: ActionBar, ActionBar

public void onContentScrollStarted()

public void onContentScrollStopped()

public boolean collapseActionView()

public abstract void setCustomView(View view)

Set the action bar into custom navigation mode, supplying a view for custom navigation. Custom navigation views appear between the application icon and any action buttons and may use any space available there. Common use cases for custom navigation views might include an auto-suggesting address bar for a browser or other navigation mechanisms that do not translate well to provided navigation modes.

Parameters:

view: Custom navigation view to place in the ActionBar.

public abstract void setCustomView(View view, ActionBar.LayoutParams layoutParams)

Set the action bar into custom navigation mode, supplying a view for custom navigation.

Custom navigation views appear between the application icon and any action buttons and may use any space available there. Common use cases for custom navigation views might include an auto-suggesting address bar for a browser or other navigation mechanisms that do not translate well to provided navigation modes.

The display option ActionBar.DISPLAY_SHOW_CUSTOM must be set for the custom view to be displayed.

Parameters:

view: Custom navigation view to place in the ActionBar.
layoutParams: How this custom view should layout in the bar.

See also: ActionBar.setDisplayOptions(int, int)

public abstract void setListNavigationCallbacks(SpinnerAdapter adapter, ActionBar.OnNavigationListener callback)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Set the adapter and navigation callback for list navigation mode. The supplied adapter will provide views for the expanded list as well as the currently selected item. (These may be displayed differently.) The supplied OnNavigationListener will alert the application when the user changes the current list selection.

Parameters:

adapter: An adapter that will provide views both to display the current navigation selection and populate views within the dropdown navigation menu.
callback: An OnNavigationListener that will receive events when the user selects a navigation item.

public abstract int getSelectedNavigationIndex()

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Get the position of the selected navigation item in list or tabbed navigation modes.

Returns:

Position of the selected item.

public abstract int getNavigationItemCount()

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Get the number of navigation items present in the current navigation mode.

Returns:

Number of navigation items.

public abstract int getTabCount()

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Returns the number of tabs currently registered with the action bar.

Returns:

Tab count

public abstract void setNavigationMode(int mode)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Set the current navigation mode.

Parameters:

mode: The new mode to set.

See also: ActionBar.NAVIGATION_MODE_STANDARD, ActionBar.NAVIGATION_MODE_LIST, ActionBar.NAVIGATION_MODE_TABS

public abstract ActionBar.Tab getTabAt(int index)

Deprecated: Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Returns the tab at the specified index.

Parameters:

index: Index value in the range 0-get

Returns:

public abstract void setIcon(Drawable icon)

Set the icon to display in the 'home' section of the action bar. The action bar will use an icon specified by its style or the activity icon by default. Whether the home section shows an icon or logo is controlled by the display option ActionBar.DISPLAY_USE_LOGO.

Parameters:

icon: Drawable to show as an icon.

See also: ActionBar.setDisplayUseLogoEnabled(boolean), ActionBar.setDisplayShowHomeEnabled(boolean)

public abstract void setIcon(Drawable icon)

Set the icon to display in the 'home' section of the action bar. The action bar will use an icon specified by its style or the activity icon by default. Whether the home section shows an icon or logo is controlled by the display option ActionBar.DISPLAY_USE_LOGO.

Parameters:

icon: Drawable to show as an icon.

See also: ActionBar.setDisplayUseLogoEnabled(boolean), ActionBar.setDisplayShowHomeEnabled(boolean)

public boolean hasIcon()

public abstract void setLogo(Drawable logo)

Set the logo to display in the 'home' section of the action bar. The action bar will use a logo specified by its style or the activity logo by default. Whether the home section shows an icon or logo is controlled by the display option ActionBar.DISPLAY_USE_LOGO.

Parameters:

logo: Drawable to show as a logo.

See also: ActionBar.setDisplayUseLogoEnabled(boolean), ActionBar.setDisplayShowHomeEnabled(boolean)

public abstract void setLogo(Drawable logo)

Set the logo to display in the 'home' section of the action bar. The action bar will use a logo specified by its style or the activity logo by default. Whether the home section shows an icon or logo is controlled by the display option ActionBar.DISPLAY_USE_LOGO.

Parameters:

logo: Drawable to show as a logo.

See also: ActionBar.setDisplayUseLogoEnabled(boolean), ActionBar.setDisplayShowHomeEnabled(boolean)

public boolean hasLogo()

public void setDefaultDisplayHomeAsUpEnabled(boolean enabled)

public boolean onKeyShortcut(int keyCode, KeyEvent ev)

Source

/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appcompat.app;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.SpinnerAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.appcompat.R;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.view.ActionBarPolicy;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.view.SupportMenuInflater;
import androidx.appcompat.view.ViewPropertyAnimatorCompatSet;
import androidx.appcompat.view.menu.MenuBuilder;
import androidx.appcompat.view.menu.MenuPopupHelper;
import androidx.appcompat.view.menu.SubMenuBuilder;
import androidx.appcompat.widget.ActionBarContainer;
import androidx.appcompat.widget.ActionBarContextView;
import androidx.appcompat.widget.ActionBarOverlayLayout;
import androidx.appcompat.widget.DecorToolbar;
import androidx.appcompat.widget.ScrollingTabContainerView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.core.view.ViewPropertyAnimatorListener;
import androidx.core.view.ViewPropertyAnimatorListenerAdapter;
import androidx.core.view.ViewPropertyAnimatorUpdateListener;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;

import java.lang.ref.WeakReference;
import java.util.ArrayList;

/**
 * WindowDecorActionBar is the ActionBar implementation used
 * by devices of all screen sizes as part of the window decor layout.
 *
 * @hide
 */
@RestrictTo(LIBRARY_GROUP_PREFIX)
public class WindowDecorActionBar extends ActionBar implements
        ActionBarOverlayLayout.ActionBarVisibilityCallback {
    private static final String TAG = "WindowDecorActionBar";

    private static final Interpolator sHideInterpolator = new AccelerateInterpolator();
    private static final Interpolator sShowInterpolator = new DecelerateInterpolator();

    Context mContext;
    private Context mThemedContext;
    private Activity mActivity;

    ActionBarOverlayLayout mOverlayLayout;
    ActionBarContainer mContainerView;
    DecorToolbar mDecorToolbar;
    ActionBarContextView mContextView;
    View mContentView;
    ScrollingTabContainerView mTabScrollView;

    private ArrayList<TabImpl> mTabs = new ArrayList<TabImpl>();

    private TabImpl mSelectedTab;
    private int mSavedTabPosition = INVALID_POSITION;

    private boolean mDisplayHomeAsUpSet;

    ActionModeImpl mActionMode;
    ActionMode mDeferredDestroyActionMode;
    ActionMode.Callback mDeferredModeDestroyCallback;

    private boolean mLastMenuVisibility;
    private ArrayList<OnMenuVisibilityListener> mMenuVisibilityListeners =
            new ArrayList<OnMenuVisibilityListener>();

    private static final int INVALID_POSITION = -1;

    // The fade duration for toolbar and action bar when entering/exiting action mode.
    private static final long FADE_OUT_DURATION_MS = 100;
    private static final long FADE_IN_DURATION_MS = 200;

    private boolean mHasEmbeddedTabs;

    private int mCurWindowVisibility = View.VISIBLE;

    boolean mContentAnimations = true;
    boolean mHiddenByApp;
    boolean mHiddenBySystem;
    private boolean mShowingForMode;

    private boolean mNowShowing = true;

    ViewPropertyAnimatorCompatSet mCurrentShowAnim;
    private boolean mShowHideAnimationEnabled;
    boolean mHideOnContentScroll;

    final ViewPropertyAnimatorListener mHideListener = new ViewPropertyAnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(View view) {
            if (mContentAnimations && mContentView != null) {
                mContentView.setTranslationY(0f);
                mContainerView.setTranslationY(0f);
            }
            mContainerView.setVisibility(View.GONE);
            mContainerView.setTransitioning(false);
            mCurrentShowAnim = null;
            completeDeferredDestroyActionMode();
            if (mOverlayLayout != null) {
                ViewCompat.requestApplyInsets(mOverlayLayout);
            }
        }
    };

    final ViewPropertyAnimatorListener mShowListener = new ViewPropertyAnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(View view) {
            mCurrentShowAnim = null;
            mContainerView.requestLayout();
        }
    };

    final ViewPropertyAnimatorUpdateListener mUpdateListener =
            new ViewPropertyAnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(View view) {
                    final ViewParent parent = mContainerView.getParent();
                    ((View) parent).invalidate();
                }
            };

    public WindowDecorActionBar(Activity activity, boolean overlayMode) {
        mActivity = activity;
        Window window = activity.getWindow();
        View decor = window.getDecorView();
        init(decor);
        if (!overlayMode) {
            mContentView = decor.findViewById(android.R.id.content);
        }
    }

    public WindowDecorActionBar(Dialog dialog) {
        init(dialog.getWindow().getDecorView());
    }

    /**
     * Only for edit mode.
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP_PREFIX)
    public WindowDecorActionBar(View layout) {
        init(layout);
    }

    private void init(View decor) {
        mOverlayLayout = (ActionBarOverlayLayout) decor.findViewById(R.id.decor_content_parent);
        if (mOverlayLayout != null) {
            mOverlayLayout.setActionBarVisibilityCallback(this);
        }
        mDecorToolbar = getDecorToolbar(decor.findViewById(R.id.action_bar));
        mContextView = (ActionBarContextView) decor.findViewById(
                R.id.action_context_bar);
        mContainerView = (ActionBarContainer) decor.findViewById(
                R.id.action_bar_container);

        if (mDecorToolbar == null || mContextView == null || mContainerView == null) {
            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
                    "with a compatible window decor layout");
        }

        mContext = mDecorToolbar.getContext();

        // This was initially read from the action bar style
        final int current = mDecorToolbar.getDisplayOptions();
        final boolean homeAsUp = (current & DISPLAY_HOME_AS_UP) != 0;
        if (homeAsUp) {
            mDisplayHomeAsUpSet = true;
        }

        ActionBarPolicy abp = ActionBarPolicy.get(mContext);
        setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);
        setHasEmbeddedTabs(abp.hasEmbeddedTabs());

        final TypedArray a = mContext.obtainStyledAttributes(null,
                R.styleable.ActionBar,
                R.attr.actionBarStyle, 0);
        if (a.getBoolean(R.styleable.ActionBar_hideOnContentScroll, false)) {
            setHideOnContentScrollEnabled(true);
        }
        final int elevation = a.getDimensionPixelSize(R.styleable.ActionBar_elevation, 0);
        if (elevation != 0) {
            setElevation(elevation);
        }
        a.recycle();
    }

    private DecorToolbar getDecorToolbar(View view) {
        if (view instanceof DecorToolbar) {
            return (DecorToolbar) view;
        } else if (view instanceof Toolbar) {
            return ((Toolbar) view).getWrapper();
        } else {
            throw new IllegalStateException("Can't make a decor toolbar out of " +
                    (view != null ? view.getClass().getSimpleName() : "null"));
        }
    }

    @Override
    public void setElevation(float elevation) {
        ViewCompat.setElevation(mContainerView, elevation);
    }

    @Override
    public float getElevation() {
        return ViewCompat.getElevation(mContainerView);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        setHasEmbeddedTabs(ActionBarPolicy.get(mContext).hasEmbeddedTabs());
    }

    private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
        mHasEmbeddedTabs = hasEmbeddedTabs;
        // Switch tab layout configuration if needed
        if (!mHasEmbeddedTabs) {
            mDecorToolbar.setEmbeddedTabView(null);
            mContainerView.setTabContainer(mTabScrollView);
        } else {
            mContainerView.setTabContainer(null);
            mDecorToolbar.setEmbeddedTabView(mTabScrollView);
        }
        final boolean isInTabMode = getNavigationMode() == NAVIGATION_MODE_TABS;
        if (mTabScrollView != null) {
            if (isInTabMode) {
                mTabScrollView.setVisibility(View.VISIBLE);
                if (mOverlayLayout != null) {
                    ViewCompat.requestApplyInsets(mOverlayLayout);
                }
            } else {
                mTabScrollView.setVisibility(View.GONE);
            }
        }
        mDecorToolbar.setCollapsible(!mHasEmbeddedTabs && isInTabMode);
        mOverlayLayout.setHasNonEmbeddedTabs(!mHasEmbeddedTabs && isInTabMode);
    }

    private void ensureTabsExist() {
        if (mTabScrollView != null) {
            return;
        }

        ScrollingTabContainerView tabScroller = new ScrollingTabContainerView(mContext);

        if (mHasEmbeddedTabs) {
            tabScroller.setVisibility(View.VISIBLE);
            mDecorToolbar.setEmbeddedTabView(tabScroller);
        } else {
            if (getNavigationMode() == NAVIGATION_MODE_TABS) {
                tabScroller.setVisibility(View.VISIBLE);
                if (mOverlayLayout != null) {
                    ViewCompat.requestApplyInsets(mOverlayLayout);
                }
            } else {
                tabScroller.setVisibility(View.GONE);
            }
            mContainerView.setTabContainer(tabScroller);
        }
        mTabScrollView = tabScroller;
    }

    void completeDeferredDestroyActionMode() {
        if (mDeferredModeDestroyCallback != null) {
            mDeferredModeDestroyCallback.onDestroyActionMode(mDeferredDestroyActionMode);
            mDeferredDestroyActionMode = null;
            mDeferredModeDestroyCallback = null;
        }
    }

    @Override
    public void onWindowVisibilityChanged(int visibility) {
        mCurWindowVisibility = visibility;
    }

    /**
     * Enables or disables animation between show/hide states.
     * If animation is disabled using this method, animations in progress
     * will be finished.
     *
     * @param enabled true to animate, false to not animate.
     */
    @Override
    public void setShowHideAnimationEnabled(boolean enabled) {
        mShowHideAnimationEnabled = enabled;
        if (!enabled && mCurrentShowAnim != null) {
            mCurrentShowAnim.cancel();
        }
    }

    @Override
    public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
        mMenuVisibilityListeners.add(listener);
    }

    @Override
    public void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
        mMenuVisibilityListeners.remove(listener);
    }

    @Override
    public void dispatchMenuVisibilityChanged(boolean isVisible) {
        if (isVisible == mLastMenuVisibility) {
            return;
        }
        mLastMenuVisibility = isVisible;

        final int count = mMenuVisibilityListeners.size();
        for (int i = 0; i < count; i++) {
            mMenuVisibilityListeners.get(i).onMenuVisibilityChanged(isVisible);
        }
    }

    @Override
    public void setCustomView(int resId) {
        setCustomView(LayoutInflater.from(getThemedContext()).inflate(resId,
                mDecorToolbar.getViewGroup(), false));
    }

    @Override
    public void setDisplayUseLogoEnabled(boolean useLogo) {
        setDisplayOptions(useLogo ? DISPLAY_USE_LOGO : 0, DISPLAY_USE_LOGO);
    }

    @Override
    public void setDisplayShowHomeEnabled(boolean showHome) {
        setDisplayOptions(showHome ? DISPLAY_SHOW_HOME : 0, DISPLAY_SHOW_HOME);
    }

    @Override
    public void setDisplayHomeAsUpEnabled(boolean showHomeAsUp) {
        setDisplayOptions(showHomeAsUp ? DISPLAY_HOME_AS_UP : 0, DISPLAY_HOME_AS_UP);
    }

    @Override
    public void setDisplayShowTitleEnabled(boolean showTitle) {
        setDisplayOptions(showTitle ? DISPLAY_SHOW_TITLE : 0, DISPLAY_SHOW_TITLE);
    }

    @Override
    public void setDisplayShowCustomEnabled(boolean showCustom) {
        setDisplayOptions(showCustom ? DISPLAY_SHOW_CUSTOM : 0, DISPLAY_SHOW_CUSTOM);
    }

    @Override
    public void setHomeButtonEnabled(boolean enable) {
        mDecorToolbar.setHomeButtonEnabled(enable);
    }

    @Override
    public void setTitle(int resId) {
        setTitle(mContext.getString(resId));
    }

    @Override
    public void setSubtitle(int resId) {
        setSubtitle(mContext.getString(resId));
    }

    @Override
    public void setSelectedNavigationItem(int position) {
        switch (mDecorToolbar.getNavigationMode()) {
            case NAVIGATION_MODE_TABS:
                selectTab(mTabs.get(position));
                break;
            case NAVIGATION_MODE_LIST:
                mDecorToolbar.setDropdownSelectedPosition(position);
                break;
            default:
                throw new IllegalStateException(
                        "setSelectedNavigationIndex not valid for current navigation mode");
        }
    }

    @Override
    public void removeAllTabs() {
        cleanupTabs();
    }

    private void cleanupTabs() {
        if (mSelectedTab != null) {
            selectTab(null);
        }
        mTabs.clear();
        if (mTabScrollView != null) {
            mTabScrollView.removeAllTabs();
        }
        mSavedTabPosition = INVALID_POSITION;
    }

    @Override
    public void setTitle(CharSequence title) {
        mDecorToolbar.setTitle(title);
    }

    @Override
    public void setWindowTitle(CharSequence title) {
        mDecorToolbar.setWindowTitle(title);
    }

    @Override
    public boolean requestFocus() {
        final ViewGroup viewGroup = mDecorToolbar.getViewGroup();
        if (viewGroup != null && !viewGroup.hasFocus()) {
            viewGroup.requestFocus();
            return true;
        }
        return false;
    }

    @Override
    public void setSubtitle(CharSequence subtitle) {
        mDecorToolbar.setSubtitle(subtitle);
    }

    @Override
    public void setDisplayOptions(int options) {
        if ((options & DISPLAY_HOME_AS_UP) != 0) {
            mDisplayHomeAsUpSet = true;
        }
        mDecorToolbar.setDisplayOptions(options);
    }

    @Override
    public void setDisplayOptions(int options, int mask) {
        final int current = mDecorToolbar.getDisplayOptions();
        if ((mask & DISPLAY_HOME_AS_UP) != 0) {
            mDisplayHomeAsUpSet = true;
        }
        mDecorToolbar.setDisplayOptions((options & mask) | (current & ~mask));
    }

    @Override
    public void setBackgroundDrawable(Drawable d) {
        mContainerView.setPrimaryBackground(d);
    }

    @Override
    public void setStackedBackgroundDrawable(Drawable d) {
        mContainerView.setStackedBackground(d);
    }

    @Override
    public void setSplitBackgroundDrawable(Drawable d) {
        // no-op. We don't support split action bars
    }

    @Override
    public View getCustomView() {
        return mDecorToolbar.getCustomView();
    }

    @Override
    public CharSequence getTitle() {
        return mDecorToolbar.getTitle();
    }

    @Override
    public CharSequence getSubtitle() {
        return mDecorToolbar.getSubtitle();
    }

    @Override
    public int getNavigationMode() {
        return mDecorToolbar.getNavigationMode();
    }

    @Override
    public int getDisplayOptions() {
        return mDecorToolbar.getDisplayOptions();
    }

    @Override
    public ActionMode startActionMode(ActionMode.Callback callback) {
        if (mActionMode != null) {
            mActionMode.finish();
        }

        mOverlayLayout.setHideOnContentScrollEnabled(false);
        mContextView.killMode();
        ActionModeImpl mode = new ActionModeImpl(mContextView.getContext(), callback);
        if (mode.dispatchOnCreate()) {
            // This needs to be set before invalidate() so that it calls
            // onPrepareActionMode()
            mActionMode = mode;
            mode.invalidate();
            mContextView.initForMode(mode);
            animateToMode(true);
            return mode;
        }
        return null;
    }

    private void configureTab(Tab tab, int position) {
        final TabImpl tabi = (TabImpl) tab;
        final ActionBar.TabListener callback = tabi.getCallback();

        if (callback == null) {
            throw new IllegalStateException("Action Bar Tab must have a Callback");
        }

        tabi.setPosition(position);
        mTabs.add(position, tabi);

        final int count = mTabs.size();
        for (int i = position + 1; i < count; i++) {
            mTabs.get(i).setPosition(i);
        }
    }

    @Override
    public void addTab(Tab tab) {
        addTab(tab, mTabs.isEmpty());
    }

    @Override
    public void addTab(Tab tab, int position) {
        addTab(tab, position, mTabs.isEmpty());
    }

    @Override
    public void addTab(Tab tab, boolean setSelected) {
        ensureTabsExist();
        mTabScrollView.addTab(tab, setSelected);
        configureTab(tab, mTabs.size());
        if (setSelected) {
            selectTab(tab);
        }
    }

    @Override
    public void addTab(Tab tab, int position, boolean setSelected) {
        ensureTabsExist();
        mTabScrollView.addTab(tab, position, setSelected);
        configureTab(tab, position);
        if (setSelected) {
            selectTab(tab);
        }
    }

    @Override
    public Tab newTab() {
        return new TabImpl();
    }

    @Override
    public void removeTab(Tab tab) {
        removeTabAt(tab.getPosition());
    }

    @Override
    public void removeTabAt(int position) {
        if (mTabScrollView == null) {
            // No tabs around to remove
            return;
        }

        int selectedTabPosition = mSelectedTab != null
                ? mSelectedTab.getPosition() : mSavedTabPosition;
        mTabScrollView.removeTabAt(position);
        TabImpl removedTab = mTabs.remove(position);
        if (removedTab != null) {
            removedTab.setPosition(-1);
        }

        final int newTabCount = mTabs.size();
        for (int i = position; i < newTabCount; i++) {
            mTabs.get(i).setPosition(i);
        }

        if (selectedTabPosition == position) {
            selectTab(mTabs.isEmpty() ? null : mTabs.get(Math.max(0, position - 1)));
        }
    }

    @Override
    public void selectTab(Tab tab) {
        if (getNavigationMode() != NAVIGATION_MODE_TABS) {
            mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
            return;
        }

        final FragmentTransaction trans;
        if (mActivity instanceof FragmentActivity && !mDecorToolbar.getViewGroup().isInEditMode()) {
            // If we're not in edit mode and our Activity is a FragmentActivity, start a tx
            trans = ((FragmentActivity) mActivity).getSupportFragmentManager()
                    .beginTransaction().disallowAddToBackStack();
        } else {
            trans = null;
        }

        if (mSelectedTab == tab) {
            if (mSelectedTab != null) {
                mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
                mTabScrollView.animateToTab(tab.getPosition());
            }
        } else {
            mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
            if (mSelectedTab != null) {
                mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
            }
            mSelectedTab = (TabImpl) tab;
            if (mSelectedTab != null) {
                mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
            }
        }

        if (trans != null && !trans.isEmpty()) {
            trans.commit();
        }
    }

    @Override
    public Tab getSelectedTab() {
        return mSelectedTab;
    }

    @Override
    public int getHeight() {
        return mContainerView.getHeight();
    }

    @Override
    public void enableContentAnimations(boolean enabled) {
        mContentAnimations = enabled;
    }

    @Override
    public void show() {
        if (mHiddenByApp) {
            mHiddenByApp = false;
            updateVisibility(false);
        }
    }

    private void showForActionMode() {
        if (!mShowingForMode) {
            mShowingForMode = true;
            if (mOverlayLayout != null) {
                mOverlayLayout.setShowingForActionMode(true);
            }
            updateVisibility(false);
        }
    }

    @Override
    public void showForSystem() {
        if (mHiddenBySystem) {
            mHiddenBySystem = false;
            updateVisibility(true);
        }
    }

    @Override
    public void hide() {
        if (!mHiddenByApp) {
            mHiddenByApp = true;
            updateVisibility(false);
        }
    }

    private void hideForActionMode() {
        if (mShowingForMode) {
            mShowingForMode = false;
            if (mOverlayLayout != null) {
                mOverlayLayout.setShowingForActionMode(false);
            }
            updateVisibility(false);
        }
    }

    @Override
    public void hideForSystem() {
        if (!mHiddenBySystem) {
            mHiddenBySystem = true;
            updateVisibility(true);
        }
    }

    @Override
    public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
        if (hideOnContentScroll && !mOverlayLayout.isInOverlayMode()) {
            throw new IllegalStateException("Action bar must be in overlay mode " +
                    "(Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
        }
        mHideOnContentScroll = hideOnContentScroll;
        mOverlayLayout.setHideOnContentScrollEnabled(hideOnContentScroll);
    }

    @Override
    public boolean isHideOnContentScrollEnabled() {
        return mOverlayLayout.isHideOnContentScrollEnabled();
    }

    @Override
    public int getHideOffset() {
        return mOverlayLayout.getActionBarHideOffset();
    }

    @Override
    public void setHideOffset(int offset) {
        if (offset != 0 && !mOverlayLayout.isInOverlayMode()) {
            throw new IllegalStateException("Action bar must be in overlay mode " +
                    "(Window.FEATURE_OVERLAY_ACTION_BAR) to set a non-zero hide offset");
        }
        mOverlayLayout.setActionBarHideOffset(offset);
    }

    static boolean checkShowingFlags(boolean hiddenByApp, boolean hiddenBySystem,
            boolean showingForMode) {
        if (showingForMode) {
            return true;
        } else if (hiddenByApp || hiddenBySystem) {
            return false;
        } else {
            return true;
        }
    }

    private void updateVisibility(boolean fromSystem) {
        // Based on the current state, should we be hidden or shown?
        final boolean shown = checkShowingFlags(mHiddenByApp, mHiddenBySystem,
                mShowingForMode);

        if (shown) {
            if (!mNowShowing) {
                mNowShowing = true;
                doShow(fromSystem);
            }
        } else {
            if (mNowShowing) {
                mNowShowing = false;
                doHide(fromSystem);
            }
        }
    }

    public void doShow(boolean fromSystem) {
        if (mCurrentShowAnim != null) {
            mCurrentShowAnim.cancel();
        }
        mContainerView.setVisibility(View.VISIBLE);

        if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled || fromSystem)) {
            // because we're about to ask its window loc
            mContainerView.setTranslationY(0f);
            float startingY = -mContainerView.getHeight();
            if (fromSystem) {
                int topLeft[] = {0, 0};
                mContainerView.getLocationInWindow(topLeft);
                startingY -= topLeft[1];
            }
            mContainerView.setTranslationY(startingY);
            ViewPropertyAnimatorCompatSet anim = new ViewPropertyAnimatorCompatSet();
            ViewPropertyAnimatorCompat a = ViewCompat.animate(mContainerView).translationY(0f);
            a.setUpdateListener(mUpdateListener);
            anim.play(a);
            if (mContentAnimations && mContentView != null) {
                mContentView.setTranslationY(startingY);
                anim.play(ViewCompat.animate(mContentView).translationY(0f));
            }
            anim.setInterpolator(sShowInterpolator);
            anim.setDuration(250);
            // If this is being shown from the system, add a small delay.
            // This is because we will also be animating in the status bar,
            // and these two elements can't be done in lock-step.  So we give
            // a little time for the status bar to start its animation before
            // the action bar animates.  (This corresponds to the corresponding
            // case when hiding, where the status bar has a small delay before
            // starting.)
            anim.setListener(mShowListener);
            mCurrentShowAnim = anim;
            anim.start();
        } else {
            mContainerView.setAlpha(1f);
            mContainerView.setTranslationY(0);
            if (mContentAnimations && mContentView != null) {
                mContentView.setTranslationY(0);
            }
            mShowListener.onAnimationEnd(null);
        }
        if (mOverlayLayout != null) {
            ViewCompat.requestApplyInsets(mOverlayLayout);
        }
    }

    public void doHide(boolean fromSystem) {
        if (mCurrentShowAnim != null) {
            mCurrentShowAnim.cancel();
        }

        if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled || fromSystem)) {
            mContainerView.setAlpha(1f);
            mContainerView.setTransitioning(true);
            ViewPropertyAnimatorCompatSet anim = new ViewPropertyAnimatorCompatSet();
            float endingY = -mContainerView.getHeight();
            if (fromSystem) {
                int topLeft[] = {0, 0};
                mContainerView.getLocationInWindow(topLeft);
                endingY -= topLeft[1];
            }
            ViewPropertyAnimatorCompat a = ViewCompat.animate(mContainerView).translationY(endingY);
            a.setUpdateListener(mUpdateListener);
            anim.play(a);
            if (mContentAnimations && mContentView != null) {
                anim.play(ViewCompat.animate(mContentView).translationY(endingY));
            }
            anim.setInterpolator(sHideInterpolator);
            anim.setDuration(250);
            anim.setListener(mHideListener);
            mCurrentShowAnim = anim;
            anim.start();
        } else {
            mHideListener.onAnimationEnd(null);
        }
    }

    @Override
    public boolean isShowing() {
        final int height = getHeight();
        // Take into account the case where the bar has a 0 height due to not being measured yet.
        return mNowShowing && (height == 0 || getHideOffset() < height);
    }

    public void animateToMode(boolean toActionMode) {
        if (toActionMode) {
            showForActionMode();
        } else {
            hideForActionMode();
        }

        if (shouldAnimateContextView()) {
            ViewPropertyAnimatorCompat fadeIn, fadeOut;
            if (toActionMode) {
                // We use INVISIBLE for the Toolbar to make sure that the container has a non-zero
                // height throughout. The context view is GONE initially, so will not have been laid
                // out when the animation starts. This can lead to the container collapsing to 0px
                // height for a short period.
                fadeOut = mDecorToolbar.setupAnimatorToVisibility(View.INVISIBLE,
                        FADE_OUT_DURATION_MS);
                fadeIn = mContextView.setupAnimatorToVisibility(View.VISIBLE,
                        FADE_IN_DURATION_MS);
            } else {
                fadeIn = mDecorToolbar.setupAnimatorToVisibility(View.VISIBLE,
                        FADE_IN_DURATION_MS);
                fadeOut = mContextView.setupAnimatorToVisibility(View.GONE,
                        FADE_OUT_DURATION_MS);
            }
            ViewPropertyAnimatorCompatSet set = new ViewPropertyAnimatorCompatSet();
            set.playSequentially(fadeOut, fadeIn);
            set.start();
        } else {
            if (toActionMode) {
                mDecorToolbar.setVisibility(View.INVISIBLE);
                mContextView.setVisibility(View.VISIBLE);
            } else {
                mDecorToolbar.setVisibility(View.VISIBLE);
                mContextView.setVisibility(View.GONE);
            }
        }
        // mTabScrollView's visibility is not affected by action mode.
    }

    private boolean shouldAnimateContextView() {
        // We only to animate the action mode in if the container view has already been laid out.
        // If it hasn't been laid out, it hasn't been drawn to screen yet.
        return ViewCompat.isLaidOut(mContainerView);
    }

    @Override
    public Context getThemedContext() {
        if (mThemedContext == null) {
            TypedValue outValue = new TypedValue();
            Resources.Theme currentTheme = mContext.getTheme();
            currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
            final int targetThemeRes = outValue.resourceId;

            if (targetThemeRes != 0) {
                mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
            } else {
                mThemedContext = mContext;
            }
        }
        return mThemedContext;
    }

    @Override
    public boolean isTitleTruncated() {
        return mDecorToolbar != null && mDecorToolbar.isTitleTruncated();
    }

    @Override
    public void setHomeAsUpIndicator(Drawable indicator) {
        mDecorToolbar.setNavigationIcon(indicator);
    }

    @Override
    public void setHomeAsUpIndicator(int resId) {
        mDecorToolbar.setNavigationIcon(resId);
    }

    @Override
    public void setHomeActionContentDescription(CharSequence description) {
        mDecorToolbar.setNavigationContentDescription(description);
    }

    @Override
    public void setHomeActionContentDescription(int resId) {
        mDecorToolbar.setNavigationContentDescription(resId);
    }

    @Override
    public void onContentScrollStarted() {
        if (mCurrentShowAnim != null) {
            mCurrentShowAnim.cancel();
            mCurrentShowAnim = null;
        }
    }

    @Override
    public void onContentScrollStopped() {
    }

    @Override
    public boolean collapseActionView() {
        if (mDecorToolbar != null && mDecorToolbar.hasExpandedActionView()) {
            mDecorToolbar.collapseActionView();
            return true;
        }
        return false;
    }

    /**
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP_PREFIX)
    public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
        private final Context mActionModeContext;
        private final MenuBuilder mMenu;

        private ActionMode.Callback mCallback;
        private WeakReference<View> mCustomView;

        public ActionModeImpl(Context context, ActionMode.Callback callback) {
            mActionModeContext = context;
            mCallback = callback;
            mMenu = new MenuBuilder(context)
                    .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            mMenu.setCallback(this);
        }

        @Override
        public MenuInflater getMenuInflater() {
            return new SupportMenuInflater(mActionModeContext);
        }

        @Override
        public Menu getMenu() {
            return mMenu;
        }

        @Override
        public void finish() {
            if (mActionMode != this) {
                // Not the active action mode - no-op
                return;
            }

            // If this change in state is going to cause the action bar
            // to be hidden, defer the onDestroy callback until the animation
            // is finished and associated relayout is about to happen. This lets
            // apps better anticipate visibility and layout behavior.
            if (!checkShowingFlags(mHiddenByApp, mHiddenBySystem, false)) {
                // With the current state but the action bar hidden, our
                // overall showing state is going to be false.
                mDeferredDestroyActionMode = this;
                mDeferredModeDestroyCallback = mCallback;
            } else {
                mCallback.onDestroyActionMode(this);
            }
            mCallback = null;
            animateToMode(false);

            // Clear out the context mode views after the animation finishes
            mContextView.closeMode();
            mOverlayLayout.setHideOnContentScrollEnabled(mHideOnContentScroll);

            mActionMode = null;
        }

        @Override
        public void invalidate() {
            if (mActionMode != this) {
                // Not the active action mode - no-op. It's possible we are
                // currently deferring onDestroy, so the app doesn't yet know we
                // are going away and is trying to use us. That's also a no-op.
                return;
            }

            mMenu.stopDispatchingItemsChanged();
            try {
                mCallback.onPrepareActionMode(this, mMenu);
            } finally {
                mMenu.startDispatchingItemsChanged();
            }
        }

        public boolean dispatchOnCreate() {
            mMenu.stopDispatchingItemsChanged();
            try {
                return mCallback.onCreateActionMode(this, mMenu);
            } finally {
                mMenu.startDispatchingItemsChanged();
            }
        }

        @Override
        public void setCustomView(View view) {
            mContextView.setCustomView(view);
            mCustomView = new WeakReference<View>(view);
        }

        @Override
        public void setSubtitle(CharSequence subtitle) {
            mContextView.setSubtitle(subtitle);
        }

        @Override
        public void setTitle(CharSequence title) {
            mContextView.setTitle(title);
        }

        @Override
        public void setTitle(int resId) {
            setTitle(mContext.getResources().getString(resId));
        }

        @Override
        public void setSubtitle(int resId) {
            setSubtitle(mContext.getResources().getString(resId));
        }

        @Override
        public CharSequence getTitle() {
            return mContextView.getTitle();
        }

        @Override
        public CharSequence getSubtitle() {
            return mContextView.getSubtitle();
        }

        @Override
        public void setTitleOptionalHint(boolean titleOptional) {
            super.setTitleOptionalHint(titleOptional);
            mContextView.setTitleOptional(titleOptional);
        }

        @Override
        public boolean isTitleOptional() {
            return mContextView.isTitleOptional();
        }

        @Override
        public View getCustomView() {
            return mCustomView != null ? mCustomView.get() : null;
        }

        @Override
        public boolean onMenuItemSelected(@NonNull MenuBuilder menu, @NonNull MenuItem item) {
            if (mCallback != null) {
                return mCallback.onActionItemClicked(this, item);
            } else {
                return false;
            }
        }

        public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
        }

        public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
            if (mCallback == null) {
                return false;
            }

            if (!subMenu.hasVisibleItems()) {
                return true;
            }

            new MenuPopupHelper(getThemedContext(), subMenu).show();
            return true;
        }

        public void onCloseSubMenu(SubMenuBuilder menu) {
        }

        @Override
        public void onMenuModeChange(@NonNull MenuBuilder menu) {
            if (mCallback == null) {
                return;
            }
            invalidate();
            mContextView.showOverflowMenu();
        }
    }

    /**
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP_PREFIX)
    public class TabImpl extends ActionBar.Tab {
        private ActionBar.TabListener mCallback;
        private Object mTag;
        private Drawable mIcon;
        private CharSequence mText;
        private CharSequence mContentDesc;
        private int mPosition = -1;
        private View mCustomView;

        @Override
        public Object getTag() {
            return mTag;
        }

        @Override
        public Tab setTag(Object tag) {
            mTag = tag;
            return this;
        }

        public ActionBar.TabListener getCallback() {
            return mCallback;
        }

        @Override
        public Tab setTabListener(ActionBar.TabListener callback) {
            mCallback = callback;
            return this;
        }

        @Override
        public View getCustomView() {
            return mCustomView;
        }

        @Override
        public Tab setCustomView(View view) {
            mCustomView = view;
            if (mPosition >= 0) {
                mTabScrollView.updateTab(mPosition);
            }
            return this;
        }

        @Override
        public Tab setCustomView(int layoutResId) {
            return setCustomView(LayoutInflater.from(getThemedContext())
                    .inflate(layoutResId, null));
        }

        @Override
        public Drawable getIcon() {
            return mIcon;
        }

        @Override
        public int getPosition() {
            return mPosition;
        }

        public void setPosition(int position) {
            mPosition = position;
        }

        @Override
        public CharSequence getText() {
            return mText;
        }

        @Override
        public Tab setIcon(Drawable icon) {
            mIcon = icon;
            if (mPosition >= 0) {
                mTabScrollView.updateTab(mPosition);
            }
            return this;
        }

        @Override
        public Tab setIcon(int resId) {
            return setIcon(AppCompatResources.getDrawable(mContext, resId));
        }

        @Override
        public Tab setText(CharSequence text) {
            mText = text;
            if (mPosition >= 0) {
                mTabScrollView.updateTab(mPosition);
            }
            return this;
        }

        @Override
        public Tab setText(int resId) {
            return setText(mContext.getResources().getText(resId));
        }

        @Override
        public void select() {
            selectTab(this);
        }

        @Override
        public Tab setContentDescription(int resId) {
            return setContentDescription(mContext.getResources().getText(resId));
        }

        @Override
        public Tab setContentDescription(CharSequence contentDesc) {
            mContentDesc = contentDesc;
            if (mPosition >= 0) {
                mTabScrollView.updateTab(mPosition);
            }
            return this;
        }

        @Override
        public CharSequence getContentDescription() {
            return mContentDesc;
        }
    }

    @Override
    public void setCustomView(View view) {
        mDecorToolbar.setCustomView(view);
    }

    @Override
    public void setCustomView(View view, LayoutParams layoutParams) {
        view.setLayoutParams(layoutParams);
        mDecorToolbar.setCustomView(view);
    }

    @Override
    public void setListNavigationCallbacks(SpinnerAdapter adapter, OnNavigationListener callback) {
        mDecorToolbar.setDropdownParams(adapter, new NavItemSelectedListener(callback));
    }

    @Override
    public int getSelectedNavigationIndex() {
        switch (mDecorToolbar.getNavigationMode()) {
            case NAVIGATION_MODE_TABS:
                return mSelectedTab != null ? mSelectedTab.getPosition() : -1;
            case NAVIGATION_MODE_LIST:
                return mDecorToolbar.getDropdownSelectedPosition();
            default:
                return -1;
        }
    }

    @Override
    public int getNavigationItemCount() {
        switch (mDecorToolbar.getNavigationMode()) {
            case NAVIGATION_MODE_TABS:
                return mTabs.size();
            case NAVIGATION_MODE_LIST:
                return mDecorToolbar.getDropdownItemCount();
            default:
                return 0;
        }
    }

    @Override
    public int getTabCount() {
        return mTabs.size();
    }

    @Override
    public void setNavigationMode(int mode) {
        final int oldMode = mDecorToolbar.getNavigationMode();
        switch (oldMode) {
            case NAVIGATION_MODE_TABS:
                mSavedTabPosition = getSelectedNavigationIndex();
                selectTab(null);
                mTabScrollView.setVisibility(View.GONE);
                break;
        }
        if (oldMode != mode && !mHasEmbeddedTabs) {
            if (mOverlayLayout != null) {
                ViewCompat.requestApplyInsets(mOverlayLayout);
            }
        }
        mDecorToolbar.setNavigationMode(mode);
        switch (mode) {
            case NAVIGATION_MODE_TABS:
                ensureTabsExist();
                mTabScrollView.setVisibility(View.VISIBLE);
                if (mSavedTabPosition != INVALID_POSITION) {
                    setSelectedNavigationItem(mSavedTabPosition);
                    mSavedTabPosition = INVALID_POSITION;
                }
                break;
        }
        mDecorToolbar.setCollapsible(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
        mOverlayLayout.setHasNonEmbeddedTabs(mode == NAVIGATION_MODE_TABS && !mHasEmbeddedTabs);
    }

    @Override
    public Tab getTabAt(int index) {
        return mTabs.get(index);
    }


    @Override
    public void setIcon(int resId) {
        mDecorToolbar.setIcon(resId);
    }

    @Override
    public void setIcon(Drawable icon) {
        mDecorToolbar.setIcon(icon);
    }

    public boolean hasIcon() {
        return mDecorToolbar.hasIcon();
    }

    @Override
    public void setLogo(int resId) {
        mDecorToolbar.setLogo(resId);
    }

    @Override
    public void setLogo(Drawable logo) {
        mDecorToolbar.setLogo(logo);
    }

    public boolean hasLogo() {
        return mDecorToolbar.hasLogo();
    }

    @Override
    public void setDefaultDisplayHomeAsUpEnabled(boolean enable) {
        if (!mDisplayHomeAsUpSet) {
            setDisplayHomeAsUpEnabled(enable);
        }
    }

    @Override
    public boolean onKeyShortcut(int keyCode, KeyEvent event) {
        if (mActionMode == null) {
            return false;
        }
        Menu menu = mActionMode.getMenu();
        if (menu != null) {
            final KeyCharacterMap kmap = KeyCharacterMap.load(
                    event != null ? event.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
            menu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
            return menu.performShortcut(keyCode, event, 0);
        }
        return false;
    }
}