上下文操作模式自定义行为 [英] Contextual Action Mode custom behavior

查看:148
本文介绍了上下文操作模式自定义行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android开发者的菜单指南它被提及:

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

的操作模式被禁止,当用户取消选择所有项目,presses返回按钮,或选择上栏左侧的完成动作上下文动作栏消失。

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()返回按钮preSS,或完成动作选择呼叫 ActionMode.Callback onDestroyActionMode()方法。

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

我的问题是如何执行自定义操作(例如吐司(行动模式退出所做选择))当用户选择完成,而另一个操作(前。吐司(行动模式退出按BACK))当用户preSS 返回

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?

推荐答案

您可以采取的解决这个问题的一种方法是使用一个主题来隐藏您创建的行动模式完成按钮。然后,您只需添加自己完成按钮来创建的每一个动作模式。很明显,你可以跟踪是否 onDestroyActionMode 被称为是因为被打的完成按钮,或后退按钮。这里是你可以应用到你需要做到这一点的活动主题。

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>

这篇关于上下文操作模式自定义行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆