Most visited

Recently visited

PopupMenu

public class PopupMenu
extends Object

java.lang.Object
   ↳ android.support.v7.widget.PopupMenu


静态库支持版本的框架PopupMenu 用于编写在Android 3.0之前的平台上运行的应用程序。 在Android 3.0或更高版本上运行时,此实现仍在使用; 它不会尝试切换到框架的实现。 请参阅框架SDK文档以了解类概述。

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

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

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

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

void dismiss ()

关闭菜单弹出。

也可以看看:

getDragToOpenListener

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

int getGravity ()

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

也可以看看:

getMenu

Menu getMenu ()

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

Returns
Menu the Menu associated with this popup

也可以看看:

getMenuInflater

MenuInflater getMenuInflater ()

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

也可以看看:

inflate

void inflate (int menuRes)

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

Parameters
menuRes int: Menu resource to inflate

setGravity

void setGravity (int gravity)

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

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

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

也可以看看:

setOnDismissListener

void setOnDismissListener (PopupMenu.OnDismissListener listener)

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

Parameters
listener PopupMenu.OnDismissListener: the listener to notify

setOnMenuItemClickListener

void setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener listener)

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

Parameters
listener PopupMenu.OnMenuItemClickListener: the listener to notify

show

void show ()

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

也可以看看:

Hooray!