Contextual Action Mode custom behavior

南笙酒味 提交于 2020-01-03 09:47:51

问题


In android developer's menu guide it is mentioned that:

The action mode is disabled and the contextual action bar disappears when the user deselects all items, presses the BACK button, or selects the Done action on the left side of the bar.

Technically, it means that mActionMode.finish(), the BACK button press, or the Done action selection call ActionMode.Callback onDestroyActionMode() method.

My question is how to perform a custom action (for example Toast("Action mode exit by Done select")) when the user selects Done, and another action (for ex. Toast("Action mode exit by BACK")) when the user press BACK?


回答1:


One approach you can take to solving this problem is using a Theme to hide the done button from action modes you create. Then, you simply add your own Done button to every action mode you create. Obviously then you can track whether onDestroyActionMode was called because of your done button being hit or by the back button. Here is a Theme that you could apply to the activities that you need to accomplish this with.

 <style name="HideActionModeCloseTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:actionModeCloseButtonStyle">@style/NoCloseButton</item>
</style>

<style name="NoCloseButton" parent="@android:style/Widget.DeviceDefault.ActionButton.CloseMode">
    <item name="android:visibility">invisible</item>
</style>


来源:https://stackoverflow.com/questions/12730404/contextual-action-mode-custom-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!