简体   繁体   English

如何删除上下文操作栏(CAB)中的默认项目?

[英]How do I delete a default item in the contextual action bar (CAB)?

There are some questions like this already made in Stack Overflow but none of the selected solutions has worked for me. 在Stack Overflow中已经有一些类似的问题,但是没有一个选择的解决方案对我有用。 These links appear to make different choices, but I tried and I could not remove the first option which is by default. 这些链接似乎做出了不同的选择,但是我尝试了并且无法删除默认情况下的第一个选项。

Link 1 Link 2 Link 3 Link 4 链接1 链接2 链接3 链接4

Ignore the item icons. 忽略项目图标。 I need to delete the item in the circle. 我需要删除圈子中的项目。

例

private class ModoAccion implements ActionMode.Callback {

   private ArrayList<Integer> listaOpciones = new ArrayList<Integer>();

    @Override
    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
        MenuInflater inflater = actionMode.getMenuInflater();
        menu.clear();
        inflater.inflate(R.menu.admin_detalle_emp_action_mode, menu);
        actionMode.invalidate();
        return true;
    }

    @Override
    public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {

        listaOpciones.add(R.id.accion_cancelar);
        listaOpciones.add(R.id.accion_guardar);

        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            if (!listaOpciones.contains(item.getItemId()))
                item.setVisible(false);
        }

        return false;
    }

    @Override
    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
        switch (menuItem.getItemId()) {
            case R.id.accion_cancelar:
                actionMode.finish(); // Action picked, so close the CAB
                return true;
            default:
                return false;
        }
    }

    @Override
    public void onDestroyActionMode(ActionMode actionMode) {
        mActionMode = null;
    }
}

You can't actually get rid of that area of the context action bar. 您实际上无法摆脱上下文操作栏的该区域。 However, you can change its drawable (even to nothing if you like) by styling your app. 但是,您可以通过设置应用样式来更改其drawable(甚至可以随意更改)。 Just override item name android:actionModeCloseDrawable and insert your own drawable. 只需覆盖项目名称android:actionModeCloseDrawable并插入您自己的drawable。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 上下文操作栏(CAB)不覆盖工具栏 - Contextual Action Bar (CAB) does not overlay Toolbar 当我单击上下文操作栏上的项目时如何插入菜单 - How to insert a menu when i click in a item on the contextual action bar 如何在上下文操作栏中创建“搜索”字段? - How do I create a “Search” field in a contextual action bar? 如何从列表适配器显示上下文操作栏? - How Do i Show Contextual Action Bar from List Adapter? 上下文操作栏无法从SQLite删除所选项目 - Contextual Action Bar unable to delete selected item from SQLite 如何使用Espresso框架单击上下文操作栏项 - How to click contextual action bar item using Espresso framework 如何向Android默认上下文操作栏添加更多选项 - How to add more options to Android default Contextual Action Bar 如何在没有长单击事件的情况下在 Android 中触发上下文操作栏 (CAB) 以便从 Android 中的 ListView 中选择多个项目 - How to trigger contextual action bar (CAB) in Android without long-click event in order to select multiple items from ListView in Android 如何使用上下文操作栏来处理汉堡包图标和插入符号图标? - How do I handle the hamburger-icon and up-caret-icon with a contextual action bar? 在上下文操作栏中,如何通过使选项卡不可单击/可滑动来禁用滑动选项卡? - How do I disable sliding tabs when in contextual action bar, by making the tabs not clickable/swipeable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM