Hiding of the Toast for long press on actionBar item Hiding of the Toast for long press on actionBar item android android

Hiding of the Toast for long press on actionBar item


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.


Probably the cleanest way to go about this is to assign a custom action view to your menu item that mimics the look of a regular one.

Since you mentioned you're using ActionBarSherlock, here's a simple example.

Imagine the following menu.xml, which gets inflated in an Activity.

<menu xmlns:android="http://schemas.android.com/apk/res/android" >    <item        android:id="@+id/ab_main_menu_dots"        android:actionLayout="@layout/ab_main_menu_dots_layout"        android:showAsAction="always"/></menu>

You can define ab_main_menu_dots_layout.xml to mimic the overflow button like this:

<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"    style="@style/Widget.Sherlock.ActionButton.Overflow"    android:layout_width="match_parent"    android:layout_height="match_parent" />

The result is a menu item that looks like an overflow button and does not display a Toast message when you long-press it, regardless of whether the native ActionBar is used or ABS. Up to you to take it from here. You want to reconsider and abide by the guidelines instead.


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.