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>
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
.You can define ab_main_menu_dots_layout.xml to mimic the overflow button like this:
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.This is how I did it:
and this is my menu:
my custom view is just an
ImageButton
:Note: don't forget to set style,
Widget.AppCompat.Toolbar.Button.Navigation
makesIamgeButton
to be shown correctly in toolbar.P.S: Personally I prefer the default behavior but this was my case: I disabled right to left support for my application and after that when I set default locale to a rtl language, toast was showing up in the wrong side! Honestly I was in hurry and didn't find out the reason but I'll appreciate if someone let me know the why, anyway this is how I passed through.
You could try to create your own custom
ActionBar
. Here is a tutorial on how to do that: Custom Action BarYou can achieve this by using custom action view as follow:
and menu inflater code is as follow:
For me the solution was using:
So instead of inflating the menu from the XML:
I created the items programmatically using MenuItemCompat:
There is a way, if you're using ActionBarSherlock. Find the ActionMenuItemView.java file in library and just comment whole onLongClick method.