没有合适的资源?快使用搜索试试~ 我知道了~
A0246上下文菜单ContextMenu1
需积分: 0 0 下载量 125 浏览量
2022-08-03
22:33:39
上传
评论
收藏 469KB PDF 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/86312872/0001-105220a2488e4835eb20f4792051fe28_thumbnail.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
4页
1.1 知识解析 1.2 功能演示 1.3 实战操作 1.4 职业素质
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/86312872/bg1.jpg)
猿圈 www.oxcoder.com
ContextMenu
1.1 知识解析
Android 中的 ContextMenu(上下文菜单)与 PC 上的鼠标右键菜单非常类似。当在 View
上,用户长按屏幕不放两秒,将会出现一个上下文菜单。 ContextMenu 不支持图示或快捷
键。
使用 Activity/Fragment 的 onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo)来创建上下文菜单。
使用 registerForContextMenu(View view)来在需要使用上下文菜单的 View 上注册
上下文菜单,此时如果在该组件上长按,则能将上下文菜单给调出来。
通过 onContextItemSelected(MenuItem item)方法来监听选项被选中事件。
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText et = (EditText)
this.findViewById(R.id.editText1);
this.registerForContextMenu(et);
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
int id = item.getItemId();
switch(id){
case R.id.item1:
![zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![avatar](https://profile-avatar.csdnimg.cn/ec32d42ef5ce405aa423bdbeac19087a_weixin_35754676.jpg!1)
kdbshi
- 粉丝: 55
- 资源: 300
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0