Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contextual Action Mode custom behavior

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?

like image 549
Johnny Doe Avatar asked Oct 04 '12 15:10

Johnny Doe


1 Answers

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>
like image 167
Justin Breitfeller Avatar answered Oct 05 '22 22:10

Justin Breitfeller