Most visited

Recently visited

Added in API level 11

PopupMenu

public class PopupMenu
extends Object

java.lang.Object
   ↳ android.widget.PopupMenu


甲PopupMenu的显示Menu在锚定到一个模式弹出窗口View 如果有空间,弹出窗口将出现在锚点视图的下方,如果没有,则会弹出。 如果IME可见,则弹出窗口将不重叠,直到它被触摸。 触摸弹出框外会解除它。

Summary

Nested classes

interface PopupMenu.OnDismissListener

用于通知应用程序菜单已关闭的回调界面。

interface PopupMenu.OnMenuItemClickListener

如果项目本身没有单独的项目点击监听器,则负责接收菜单项点击事件。

Public constructors

PopupMenu(Context context, View anchor)

构造函数用锚点视图创建一个新的弹出式菜单。

PopupMenu(Context context, View anchor, int gravity)

构造函数用锚点视图和对齐重力创建新的弹出式菜单。

PopupMenu(Context context, View anchor, int gravity, int popupStyleAttr, int popupStyleRes)

构造函数a创建一个具有特定样式的新弹出式菜单。

Public methods

void dismiss()

关闭菜单弹出。

View.OnTouchListener getDragToOpenListener()

返回 View.OnTouchListener ,可将其添加到锚视图以实现拖动打开行为。

int getGravity()
Menu getMenu()

返回与此弹出 Menu关联的 Menu

MenuInflater getMenuInflater()
void inflate(int menuRes)

将菜单资源充入此PopupMenu。

void setGravity(int gravity)

设置用于将弹出窗口与其锚点视图对齐的重力。

void setOnDismissListener(PopupMenu.OnDismissListener listener)

设置一个监听器,当这个菜单被解除时将会收到通知。

void setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener)

设置一个侦听器,当用户从菜单中选择一个项目时将收到通知。

void show()

显示锚定到施工期间指定的视图的菜单弹出窗口。

Inherited methods

From class java.lang.Object

Public constructors

PopupMenu

Added in API level 11
PopupMenu (Context context, 
                View anchor)

构造函数用锚点视图创建一个新的弹出式菜单。

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

Added in API level 19
PopupMenu (Context context, 
                View anchor, 
                int 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

Added in API level 22
PopupMenu (Context context, 
                View anchor, 
                int gravity, 
                int popupStyleAttr, 
                int popupStyleRes)

构造函数a创建一个具有特定样式的新弹出式菜单。

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

dismiss

Added in API level 11
void dismiss ()

关闭菜单弹出。

也可以看看:

getDragToOpenListener

Added in API level 19
View.OnTouchListener getDragToOpenListener ()

返回一个 View.OnTouchListener ,可将其添加到锚视图以实现拖动打开行为。

将侦听器设置在视图上时,触摸该视图并在其边界之外拖动将打开弹出窗口。 提升将选择当前触摸的列表项目。

用法示例:

 PopupMenu myPopup = new PopupMenu(context, myAnchor);
 myAnchor.setOnTouchListener(myPopup.getDragToOpenListener());
 

Returns
View.OnTouchListener a touch listener that controls drag-to-open behavior

getGravity

Added in API level 23
int getGravity ()

Returns
int the gravity used to align the popup window to its anchor view

也可以看看:

getMenu

Added in API level 11
Menu getMenu ()

返回与此弹出Menu关联的Menu 在调用show()之前用项目填充返回的菜单。

Returns
Menu the Menu associated with this popup

也可以看看:

getMenuInflater

Added in API level 11
MenuInflater getMenuInflater ()

Returns
MenuInflater a MenuInflater that can be used to inflate menu items from XML into the menu returned by getMenu()

也可以看看:

inflate

Added in API level 14
void inflate (int menuRes)

将菜单资源充入此PopupMenu。 这相当于拨打popupMenu.getMenuInflater().inflate(menuRes, popupMenu.getMenu())

Parameters
menuRes int: Menu resource to inflate

setGravity

Added in API level 23
void setGravity (int gravity)

设置用于将弹出窗口与其锚点视图对齐的重力。

如果弹出窗口显示,则调用此方法仅在下次显示弹出窗口时生效。

Parameters
gravity int: the gravity used to align the popup window

也可以看看:

setOnDismissListener

Added in API level 14
void setOnDismissListener (PopupMenu.OnDismissListener listener)

设置一个监听器,当这个菜单被解除时将会收到通知。

Parameters
listener PopupMenu.OnDismissListener: the listener to notify

setOnMenuItemClickListener

Added in API level 11
void setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener listener)

设置一个侦听器,当用户从菜单中选择一个项目时将收到通知。

Parameters
listener PopupMenu.OnMenuItemClickListener: the listener to notify

show

Added in API level 11
void show ()

显示锚定到施工期间指定的视图的菜单弹出窗口。

也可以看看:

Hooray!