Prevent to cancel Action Mode by press back button
2016-06-24 16:58
309 查看
Action mode started by calling
action mode.
This is an interesting problem. When the ActionMode is active the back key event is consumed internally. The event is
not propagated to either
Fortunately, you can use
You might wonder what will be the behavior in case you have a submenu in the ActionMode and you close it with the back key. In this case
The above code works also with ActionBarSherlock. The only problem I found is on Android 3.1 device when the native ActionMode is used, in this case the
转自:http://stackoverflow.com/questions/11725729/prevent-to-cancel-action-mode-by-press-back-button
getActivity().startActionMode(calback);is automatically canceled after back button pressed. Is possible avoid this behavior? I need to do another operation after back button was pressed in some situation during
action mode.
This is an interesting problem. When the ActionMode is active the back key event is consumed internally. The event is
not propagated to either
onBackPressed()or
onKeyUp(int keyCode, KeyEvent event)callbacks.
Fortunately, you can use
dispatchKeyEvent(KeyEvent event)which is still called.
@Override public boolean dispatchKeyEvent(KeyEvent event) { if(mActionModeIsActive) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { // handle your back button code here return true; // consumes the back key event - ActionMode is not finished } } return super.dispatchKeyEvent(event); }
You might wonder what will be the behavior in case you have a submenu in the ActionMode and you close it with the back key. In this case
dispatchKeyEvent()is not called so you can safely use the code.
The above code works also with ActionBarSherlock. The only problem I found is on Android 3.1 device when the native ActionMode is used, in this case the
dispatchKeyEvent()is not called. Use ActionBarSherlock's ActionMode to solve it.
转自:http://stackoverflow.com/questions/11725729/prevent-to-cancel-action-mode-by-press-back-button
相关文章推荐
- iPhone 7触控Home键曝光 安卓“大白式”造型
- java.lang.Long cannot be cast to java.lang.Integer解决办法
- .Net Core Linux centos7行—.net core json 配置文件
- nginx日志切割
- javaee项目开发中为什么将jsp页面放到WEN-INF下
- Linux 系统相关知识记录
- linux查看版本信息,显卡信息
- JVM 垃圾回收器工作原理及使用实例介绍
- SwitchHosts高效切换host -- 让开发,测试,线上环境切换更容易
- 直播评论发弹幕切图功能点集合
- Spring中注解的使用详解
- js 打包 压缩后台代码 (java)
- Windows下boost使用
- <JAVA学习笔记4>——进程、线程简单介绍
- UCT算法初探
- Chrome 控制台console的用法
- vs2015将网站发布到mircosoft azure上
- Java文件下载乱码问题
- spyder 快捷键 介绍
- OPPO竞拍巴萨签名版R9 你猜卖了多少钱?