Class ActionMode
Developer Guides
For information about how to provide contextual actions with ActionMode
,
read the Menus
developer guide.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback interface for action modes. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default value to hide the action mode forinvalid reference
ViewConfiguration#getDefaultActionModeHideDuration()
static final int
The action mode is treated as a Floating Toolbar.static final int
The action mode is treated as a Primary mode. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
finish()
Finish and close this action mode.abstract View
Returns the current custom view for this action mode.abstract Menu
getMenu()
Returns the menu of actions that this action mode presents.abstract CharSequence
Returns the current subtitle of this action mode.getTag()
Retrieve the tag object associated with this ActionMode.abstract CharSequence
getTitle()
Returns the current title of this action mode.boolean
int
getType()
Returns the type for this action mode.void
hide
(long duration) Hide the action mode view from obstructing the content below for a short duration.abstract void
Invalidate the action mode and refresh menu content.void
Invalidate the content rect associated to this ActionMode.boolean
boolean
Returns whether the UI presenting this action mode can take focus or not.void
onWindowFocusChanged
(boolean hasWindowFocus) Called when the window containing the view that started this action mode gains or loses focus.abstract void
setCustomView
(View view) Set a custom view for this action mode.abstract void
setSubtitle
(CharSequence subtitle) Set the subtitle of the action mode.void
Set a tag object associated with this ActionMode.abstract void
setTitle
(CharSequence title) Set the title of the action mode.void
setTitleOptionalHint
(boolean titleOptional) Set whether or not the title/subtitle display for this action mode is optional.void
setType
(int type) Set a type for this action mode.
-
Field Details
-
TYPE_PRIMARY
public static final int TYPE_PRIMARYThe action mode is treated as a Primary mode. This is the default. Use withsetType(int)
.- See Also:
-
TYPE_FLOATING
public static final int TYPE_FLOATINGThe action mode is treated as a Floating Toolbar. Use withsetType(int)
.- See Also:
-
DEFAULT_HIDE_DURATION
public static final int DEFAULT_HIDE_DURATIONDefault value to hide the action mode forinvalid reference
ViewConfiguration#getDefaultActionModeHideDuration()
- See Also:
-
-
Constructor Details
-
ActionMode
public ActionMode()
-
-
Method Details
-
setTag
Set a tag object associated with this ActionMode.Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.
- Parameters:
tag
- Tag to associate with this ActionMode- See Also:
-
getTag
Retrieve the tag object associated with this ActionMode.Like the tag available to views, this allows applications to associate arbitrary data with an ActionMode for later reference.
- Returns:
- Tag associated with this ActionMode
- See Also:
-
setTitle
Set the title of the action mode. This method will have no visible effect if a custom view has been set.- Parameters:
title
- Title string to set- See Also:
-
setSubtitle
Set the subtitle of the action mode. This method will have no visible effect if a custom view has been set.- Parameters:
subtitle
- Subtitle string to set- See Also:
-
setTitleOptionalHint
public void setTitleOptionalHint(boolean titleOptional) Set whether or not the title/subtitle display for this action mode is optional.In many cases the supplied title for an action mode is merely meant to add context and is not strictly required for the action mode to be useful. If the title is optional, the system may choose to hide the title entirely rather than truncate it due to a lack of available space.
Note that this is merely a hint; the underlying implementation may choose to ignore this setting under some circumstances.
- Parameters:
titleOptional
- true if the title only presents optional information.
-
getTitleOptionalHint
public boolean getTitleOptionalHint()- Returns:
- true if this action mode has been given a hint to consider the title/subtitle display to be optional.
- See Also:
-
isTitleOptional
public boolean isTitleOptional()- Returns:
- true if this action mode considers the title and subtitle fields as optional. Optional titles may not be displayed to the user.
-
setCustomView
Set a custom view for this action mode. The custom view will take the place of the title and subtitle. Useful for things like search boxes.- Parameters:
view
- Custom view to use in place of the title/subtitle.- See Also:
-
setType
public void setType(int type) Set a type for this action mode. This will affect how the system renders the action mode if it has to.- Parameters:
type
- One ofTYPE_PRIMARY
orTYPE_FLOATING
.
-
getType
public int getType()Returns the type for this action mode.- Returns:
- One of
TYPE_PRIMARY
orTYPE_FLOATING
.
-
invalidate
public abstract void invalidate()Invalidate the action mode and refresh menu content. The mode'sActionMode.Callback
will have itsActionMode.Callback.onPrepareActionMode(ActionMode, Menu)
method called. If it returns true the menu will be scanned for updated content and any relevant changes will be reflected to the user. -
invalidateContentRect
public void invalidateContentRect()Invalidate the content rect associated to this ActionMode. This only makes sense for action modes that support dynamic positioning on the screen, and provides a more efficient way to reposition it without invalidating the whole action mode.- See Also:
-
hide
public void hide(long duration) Hide the action mode view from obstructing the content below for a short duration. This only makes sense for action modes that support dynamic positioning on the screen. If this method is called again before the hide duration expires, the later hide call will cancel the former and then take effect. NOTE that there is an internal limit to how long the mode can be hidden for. It's typically about a few seconds.- Parameters:
duration
- The number of milliseconds to hide for.- See Also:
-
finish
public abstract void finish()Finish and close this action mode. The action mode'sActionMode.Callback
will have itsActionMode.Callback.onDestroyActionMode(ActionMode)
method called. -
getMenu
Returns the menu of actions that this action mode presents.- Returns:
- The action mode's menu.
-
getTitle
Returns the current title of this action mode.- Returns:
- Title text
-
getSubtitle
Returns the current subtitle of this action mode.- Returns:
- Subtitle text
-
getCustomView
Returns the current custom view for this action mode.- Returns:
- The current custom view
-
onWindowFocusChanged
public void onWindowFocusChanged(boolean hasWindowFocus) Called when the window containing the view that started this action mode gains or loses focus.- Parameters:
hasWindowFocus
- True if the window containing the view that started this action mode now has focus, false otherwise.
-
isUiFocusable
@Internal public boolean isUiFocusable()Returns whether the UI presenting this action mode can take focus or not. This is used by internal components within the framework that would otherwise present an action mode UI that requires focus, such as an EditText as a custom view.- Returns:
- true if the UI used to show this action mode can take focus
-