在 android 开发者的menu guide据说:
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.
从技术上讲,这意味着 mActionMode.finish()
、BACK
按钮按下或 Done
操作选择调用 ActionMode .回调 onDestroyActionMode()
方法。
我的问题是如何在用户选择 Done
和另一个操作时执行自定义操作(例如 Toast("Action mode exit by Done select")
) (例如 Toast("Action mode exit by BACK")
)当用户按下 BACK
时?
最佳答案
解决此问题的一种方法是使用主题从您创建的操作模式中隐藏完成按钮。然后,您只需将自己的“完成”按钮添加到您创建的每个操作模式。显然,您可以跟踪 onDestroyActionMode
是否因为您的完成按钮被点击或后退按钮被调用。这是一个主题,您可以将其应用于完成此任务所需的 Activity 。
<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>
关于android - 上下文操作模式自定义行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12730404/