How to hide the share action (which use most) icon near the share action provider?

前端 未结 3 1652
无人及你
无人及你 2020-11-30 08:21

See the picture. How can i hide the icon \"P\" which means share to Pinterest?

\"enter

3条回答
  •  醉梦人生
    2020-11-30 08:40

    I found a way to work around this. I am using support library 23.0.1, I have not tested this on other support library versions.

    The solution is easy, when you create ShareActionProvider, just override method onCreateActionView() and return null for it. Then you can track all history in the popup menu, but the history will not be shown in toolbar.

    Here is a code sample:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuItem item = menu.add(Menu.NONE, R.id.menu_share, Menu.NONE, R.string.share);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        mShareActionProvider = new ShareActionProvider(this) {
            @Override
            public View onCreateActionView() {
                return null;
            }
        };
        item.setIcon(R.drawable.abc_ic_menu_share_mtrl_alpha);
        MenuItemCompat.setActionProvider(item, mShareActionProvider);
        return true;
    }
    

    Currently I have not found any problem using this work around.

提交回复
热议问题