public class PopupMenu
extends Object
| java.lang.Object | |
| android.widget.PopupMenu | |
甲PopupMenu的显示Menu在锚定到一个模式弹出窗口View 。 如果有空间,弹出窗口将出现在锚点视图的下方,如果没有,则会弹出。 如果IME可见,则弹出窗口将不重叠,直到它被触摸。 触摸弹出框外会解除它。
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() 返回 |
int |
getGravity() |
Menu |
getMenu() |
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) |
|
|---|---|
java.lang.Object
|
|
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 (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 (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. |
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 |
int getGravity ()
| 返回(Returns) | |
|---|---|
int |
the gravity used to align the popup window to its anchor view |
也可以看看:
Menu getMenu ()
返回与此弹出Menu关联的Menu 。 在调用show()之前用项目填充返回的菜单。
| 返回(Returns) | |
|---|---|
Menu |
the Menu associated with this popup |
也可以看看:
MenuInflater getMenuInflater ()
| 返回(Returns) | |
|---|---|
MenuInflater |
a MenuInflater that can be used to inflate menu items from XML into the menu returned by getMenu() |
也可以看看:
void inflate (int menuRes)
将菜单资源充入此PopupMenu。 这相当于拨打popupMenu.getMenuInflater().inflate(menuRes, popupMenu.getMenu()) 。
| 参数(Parameters) | |
|---|---|
menuRes |
int: Menu resource to inflate |
void setGravity (int gravity)
设置用于将弹出窗口与其锚点视图对齐的重力。
如果弹出窗口显示,则调用此方法仅在下次显示弹出窗口时生效。
| 参数(Parameters) | |
|---|---|
gravity |
int: the gravity used to align the popup window |
也可以看看:
void setOnDismissListener (PopupMenu.OnDismissListener listener)
设置一个监听器,当这个菜单被解除时将会收到通知。
| 参数(Parameters) | |
|---|---|
listener |
PopupMenu.OnDismissListener: the listener to notify |
void setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener listener)
设置一个侦听器,当用户从菜单中选择一个项目时将收到通知。
| 参数(Parameters) | |
|---|---|
listener |
PopupMenu.OnMenuItemClickListener: the listener to notify |