Hiding of the Toast for long press on actionBar it

2019-01-15 06:07发布

Is some possible way how to hide the toast after long-press on the ActionBar item? I didn't setup a title for the item but it is still there - empty toast.

<item
    android:id="@+id/ab_main_menu_dots"
    android:icon="@drawable/action_icons_dots"
    android:showAsAction="always">
    <menu>
        <item
            android:id="@+id/ab_main_menu_my_profile"
            android:showAsAction="never"
            android:title="@string/ab_my_profile">
        </item>
        <item
            android:id="@+id/ab_main_menu_settings"
            android:showAsAction="never"
            android:title="@string/menu_settings">
        </item>
        <item
            android:id="@+id/ab_main_menu_help"
            android:showAsAction="never"
            android:title="@string/tv_help_login">
        </item>
        <item
            android:id="@+id/ab_main_menu_about_us"
            android:showAsAction="never"
            android:title="@string/ab_about_us">
        </item>
        <item
            android:id="@+id/ab_main_menu_logout"
            android:showAsAction="never"
            android:title="@string/bt_logout_main">
        </item>
    </menu>
</item>

9条回答
Emotional °昔
2楼-- · 2019-01-15 06:55

You can modify onLongClickin ActionMenuItemView Class to stop Toasting on long click.
but be careful, It's only working on devices with API less than 11, because sherlockactionbar library checking your device API level by Build.VERSION.SDK_INT and if you have newer device it just use default system actionbar which you're not modifying.

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-15 06:56

In onCreateOptionsMenu schedule a task to disable long click on desired menu item. Here is the sample

    @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    inflater.inflate(R.menu.my_menu, menu);
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            final View v = getActivity().findViewById(R.id.your_menu_item);
            if (v != null) {
                v.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        return false;
                    }
                });
            }
        }
    });
}
查看更多
劳资没心,怎么记你
4楼-- · 2019-01-15 07:08

The only way to hide the toast is when you set the ActionBar menu item to be displayed with text. android:showAsAction="withText". Otherwise the toast adds clarification of what each action item represents even if there is no title set for menu item.

查看更多
登录 后发表回答