android - 在 Android 中长按时从操作模式中删除后退/主页按钮

标签 android contextual-action-bar android-actionmode actionmode

我已经在回收器 View 内实现了长按上下文操作模式。为此,我从创建操作模式中调用了 ActionModeCallback

创建 Action 模式时,默认显示后退箭头。 检查如下:

enter image description here

点击后退箭头,操作模式将关闭。

现在我想隐藏删除默认后退按钮,该按钮与android中的操作模式一起出现。

注意:已经尝试过 getActionBar().setDisplayHomeAsUpEnabled(false). 但它不起作用。请帮忙。

编辑:

谢谢问题已解决: 添加style.xml后

<item name="actionModeCloseDrawable">@color/colorPrimary</item>
    <item name="actionModeCloseButtonStyle">@style/Widget.AppCompat.ActionMode</item>

最佳答案

尝试以下方法将其完全删除:

ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.setHomeButtonEnabled(false);      
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false); 
}

更新

或尝试使用自定义主题

<style name="yourTheme" parent="theThemeYouUse">
    <item name="android:actionModeCloseDrawable">@drawable/yourBack</item>
</style>

并在 list 中:

<activity
        android:name="yourActivity"
        android:theme="@style/yourTheme"
  ...
/>

关于android - 在 Android 中长按时从操作模式中删除后退/主页按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38138881/

相关文章:

android - 如何自定义 float ActionBar的背景?

android - 如何去除透明 ActionBar 的标题背景?

javascript - Cordova FileTransfer 插件参数在 Android 上为空

android - 带有 DialogFragment 的上下文操作栏

java - 用户界面 : Action Bar and Contextual Action Bar, 新趋势

android - 如何在 SearchView 中禁用 ActionMode

javascript - 拒绝加载脚本,因为它违反了以下内容安全策略指令

android - 在 fragment 内初始化 map

java - 无法从扩展 DialogFragment 的类创建默认构造函数,我已经创建了自己的自定义构造函数