敢说敢作敢为, 无怨无恨无悔。这篇文章主要讲述Android Menu相关的知识,希望能为你提供帮助。
Menu
1.ContextMenu
上下文菜单,就是长按某个控件后弹出菜单1.1选项菜单Menu
<
?xml version="
1.0"
encoding="
utf-8"
?>
<
menu xmlns:android="
http://schemas.android.com/apk/res/android"
>
<
group android:checkableBehavior="
none"
>
<
item android:id="
@+id/item_context_item1"
android:title="
Item1"
/>
<
item android:id="
@+id/item_context_item2"
android:title="
Item2"
/>
<
item android:id="
@+id/item_context_item3"
android:title="
Item3"
/>
<
/group>
<
/menu>
1.2 为View注册上下文菜单
registerForContextMenu(view);
1.3创建Menu
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {MenuInflater inflator=new MenuInflater(this);
inflator.inflate(R.menu.menu_context,menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
【Android Menu】1.4 Item 点击事件
@Override
public boolean onContextItemSelected(MenuItem item) {switch (item.getItemId()){
case R.id.item_context_item1:
toast("
Item1"
);
break;
....
}
return super.onContextItemSelected(item);
}
2.PopupMenu
// Show Popup Menu
void showPopupMenu(){// 为View指定 PopupMenu
PopupMenu pm=new PopupMenu(MenuActivity.this,btnPopupMenu);
// 指定 Menu 文件
pm.getMenuInflater().inflate(R.menu.menu_test,pm.getMenu());
//Item 点击事件
pm.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.menu_item1:
toast("
Menu1"
);
break;
case R.id.menu_item2:
toast("
Menu2"
);
break;
}
return true;
}
});
pm.show();
//显示
}
推荐阅读
- Android - ViewPager
- AnnotationConfigApplicationContext
- Android 博客导航
- java/android ?????????????????????????????????(17)
- Appium自动化WebView中元素的操作
- [CF348B]Apple Tree
- Appium环境搭建(Java版本)
- android appium微信等自动化的那些坑儿
- Appium 解决微信公众号小程序切换 webview 后无法定位元素的问题