Action mode started by calling 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.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
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()
oronKeyUp(int keyCode, KeyEvent event)
callbacks.Fortunately, you can use
dispatchKeyEvent(KeyEvent event)
which is still called.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.Create your own Window.Callback and intercept event before it is passed to AppCompatDelegateImplBase.
In your own delegate :
When you destroy action mode, restore reference to previous delegate
You own delegate signature:
public class WindowCallbackDelegate implements Window.Callback {...}
Suggested solutions did not work for me. So I decide to create
back
event manually. I needed this event in my fragment so I createdBaseFragment
that all my fragments will extend.Main fragment