belongs to Maven artifact com.android.support:appcompat-v7:28.0.0-alpha1
PopupMenu
public
class
PopupMenu
extends Object
java.lang.Object | |
↳ | android.support.v7.widget.PopupMenu |
Static library support version of the framework's PopupMenu
.
Used to write apps that run on platforms prior to Android 3.0. When running
on Android 3.0 or above, this implementation is still used; it does not try
to switch to the framework's implementation. See the framework SDK
documentation for a class overview.
Summary
Nested classes | |
---|---|
interface |
PopupMenu.OnDismissListener
Callback interface used to notify the application that the menu has closed. |
interface |
PopupMenu.OnMenuItemClickListener
Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. |
Public constructors | |
---|---|
PopupMenu(Context context, View anchor)
Constructor to create a new popup menu with an anchor view. |
|
PopupMenu(Context context, View anchor, int gravity)
Constructor to create a new popup menu with an anchor view and alignment gravity. |
|
PopupMenu(Context context, View anchor, int gravity, int popupStyleAttr, int popupStyleRes)
Constructor a create a new popup menu with a specific style. |
Public methods | |
---|---|
void
|
dismiss()
Dismiss the menu popup. |
View.OnTouchListener
|
getDragToOpenListener()
Returns an |
int
|
getGravity()
|
Menu
|
getMenu()
Returns the |
MenuInflater
|
getMenuInflater()
|
void
|
inflate(int menuRes)
Inflate a menu resource into this PopupMenu. |
void
|
setGravity(int gravity)
Sets the gravity used to align the popup window to its anchor view. |
void
|
setOnDismissListener(PopupMenu.OnDismissListener listener)
Sets a listener that will be notified when this menu is dismissed. |
void
|
setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener)
Sets a listener that will be notified when the user selects an item from the menu. |
void
|
show()
Show the menu popup anchored to the view specified during construction. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
Public constructors
PopupMenu
PopupMenu (Context context, View anchor)
Constructor to create a new popup menu with an anchor view.
Parameters | |
---|---|
context |
Context : Context the popup menu is running in, through which it
can access the current theme, resources, etc. |
anchor |
View : Anchor view for this popup. The popup will appear below
the anchor if there is room, or above it if there is not.
|
PopupMenu
PopupMenu (Context context, View anchor, int gravity)
Constructor to create a new popup menu with an anchor view and alignment gravity.
Parameters | |
---|---|
context |
Context : Context the popup menu is running in, through which it
can access the current theme, resources, etc. |
anchor |
View : Anchor view for this popup. The popup will appear below
the anchor if there is room, or above it if there is not. |
gravity |
int : The Gravity value for aligning the popup with its
anchor.
|
PopupMenu
PopupMenu (Context context, View anchor, int gravity, int popupStyleAttr, int popupStyleRes)
Constructor a create a new popup menu with a specific style.
Parameters | |
---|---|
context |
Context : Context the popup menu is running in, through which it
can access the current theme, resources, etc. |
anchor |
View : Anchor view for this popup. The popup will appear below
the anchor if there is room, or above it if there is not. |
gravity |
int : The Gravity value for aligning the popup with its
anchor. |
popupStyleAttr |
int : An attribute in the current theme that contains a
reference to a style resource that supplies default values for
the popup window. Can be 0 to not look for defaults. |
popupStyleRes |
int : A resource identifier of a style resource that
supplies default values for the popup window, used only if
popupStyleAttr is 0 or can not be found in the theme. Can be 0
to not look for defaults.
|
Public methods
getDragToOpenListener
View.OnTouchListener getDragToOpenListener ()
Returns an View.OnTouchListener
that can be added to the anchor view
to implement drag-to-open behavior.
When the listener is set on a view, touching that view and dragging outside of its bounds will open the popup window. Lifting will select the currently touched list item.
Example usage:
PopupMenu myPopup = new PopupMenu(context, myAnchor); myAnchor.setOnTouchListener(myPopup.getDragToOpenListener());
Returns | |
---|---|
View.OnTouchListener |
a touch listener that controls drag-to-open behavior |
getGravity
int getGravity ()
Returns | |
---|---|
int |
the gravity used to align the popup window to its anchor view |
See also:
getMenu
Menu getMenu ()
Returns the Menu
associated with this popup. Populate the
returned Menu with items before calling show()
.
Returns | |
---|---|
Menu |
the Menu associated with this popup |
See also:
getMenuInflater
MenuInflater getMenuInflater ()
Returns | |
---|---|
MenuInflater |
a MenuInflater that can be used to inflate menu items
from XML into the menu returned by getMenu() |
See also:
inflate
void inflate (int menuRes)
Inflate a menu resource into this PopupMenu. This is equivalent to
calling popupMenu.getMenuInflater().inflate(menuRes, popupMenu.getMenu())
.
Parameters | |
---|---|
menuRes |
int : Menu resource to inflate
|
setGravity
void setGravity (int gravity)
Sets the gravity used to align the popup window to its anchor view.
If the popup is showing, calling this method will take effect only the next time the popup is shown.
Parameters | |
---|---|
gravity |
int : the gravity used to align the popup window |
See also:
setOnDismissListener
void setOnDismissListener (PopupMenu.OnDismissListener listener)
Sets a listener that will be notified when this menu is dismissed.
Parameters | |
---|---|
listener |
PopupMenu.OnDismissListener : the listener to notify
|
setOnMenuItemClickListener
void setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener listener)
Sets a listener that will be notified when the user selects an item from the menu.
Parameters | |
---|---|
listener |
PopupMenu.OnMenuItemClickListener : the listener to notify
|
show
void show ()
Show the menu popup anchored to the view specified during construction.
See also:
Annotations
Interfaces
- ActionMenuView.OnMenuItemClickListener
- PopupMenu.OnDismissListener
- PopupMenu.OnMenuItemClickListener
- RecyclerView.ChildDrawingOrderCallback
- RecyclerView.ItemAnimator.ItemAnimatorFinishedListener
- RecyclerView.LayoutManager.LayoutPrefetchRegistry
- RecyclerView.OnChildAttachStateChangeListener
- RecyclerView.OnItemTouchListener
- RecyclerView.RecyclerListener
- RecyclerView.SmoothScroller.ScrollVectorProvider
- SearchView.OnCloseListener
- SearchView.OnQueryTextListener
- SearchView.OnSuggestionListener
- ShareActionProvider.OnShareTargetSelectedListener
- ThemedSpinnerAdapter
- Toolbar.OnMenuItemClickListener
Classes
- ActionMenuView
- ActionMenuView.LayoutParams
- AppCompatAutoCompleteTextView
- AppCompatButton
- AppCompatCheckBox
- AppCompatCheckedTextView
- AppCompatEditText
- AppCompatImageButton
- AppCompatImageView
- AppCompatMultiAutoCompleteTextView
- AppCompatRadioButton
- AppCompatRatingBar
- AppCompatSeekBar
- AppCompatSpinner
- AppCompatTextView
- CardView
- DefaultItemAnimator
- DividerItemDecoration
- GridLayout
- GridLayout.Alignment
- GridLayout.LayoutParams
- GridLayout.Spec
- GridLayoutManager
- GridLayoutManager.DefaultSpanSizeLookup
- GridLayoutManager.LayoutParams
- GridLayoutManager.SpanSizeLookup
- LinearLayoutCompat
- LinearLayoutCompat.LayoutParams
- LinearLayoutManager
- LinearLayoutManager.LayoutChunkResult
- LinearSmoothScroller
- LinearSnapHelper
- ListPopupWindow
- OrientationHelper
- PagerSnapHelper
- PopupMenu
- RecyclerView
- RecyclerView.Adapter
- RecyclerView.AdapterDataObserver
- RecyclerView.EdgeEffectFactory
- RecyclerView.ItemAnimator
- RecyclerView.ItemAnimator.ItemHolderInfo
- RecyclerView.ItemDecoration
- RecyclerView.LayoutManager
- RecyclerView.LayoutManager.Properties
- RecyclerView.LayoutParams
- RecyclerView.OnFlingListener
- RecyclerView.OnScrollListener
- RecyclerView.RecycledViewPool
- RecyclerView.Recycler
- RecyclerView.SimpleOnItemTouchListener
- RecyclerView.SmoothScroller
- RecyclerView.SmoothScroller.Action
- RecyclerView.State
- RecyclerView.ViewCacheExtension
- RecyclerView.ViewHolder
- RecyclerViewAccessibilityDelegate
- RecyclerViewAccessibilityDelegate.ItemDelegate
- SearchView
- ShareActionProvider
- SimpleItemAnimator
- SnapHelper
- StaggeredGridLayoutManager
- StaggeredGridLayoutManager.LayoutParams
- SwitchCompat
- ThemedSpinnerAdapter.Helper
- Toolbar
- Toolbar.LayoutParams
- Toolbar.SavedState
- TooltipCompat
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.