How to change a button with three dots on android to another button

I want to change the three dots button on Android to another button, which is the Add button. How to do it? I changed the button setting in my drawable, but it will offer three buttons.

thanks

+9
source share
6 answers

Sorry, I cannot reply as a comment, but I assume that you want to change the action bar overflow menu icon. If so, you can do it in styles.xml .

<!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item> </style> <!-- Style to replace actionbar overflow icon. set item 'android:actionOverflowButtonStyle' in AppTheme --> <style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow"> <item name="android:src">@drawable/ic_launcher</item> </style> 

Original message: How to change the menu menu icon in the action bar?

+23
source

Sorry, I do not have enough reputation to leave a comment. Here is the best answer I found, its one line of code:

 myToolbar.setOverflowIcon(ContextCompat.getDrawable(getApplicationContext(),R.drawable.my_drawable)); 

A link to the original answer is here: fooobar.com/questions/176594 / ...

+7
source
 //just edit menu.xml file //add icon for item which will change default setting icon //add sub menus ///menu.xml file <item android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" android:icon="@drawable/your_icon" app:showAsAction="always" > <menu> <item android:id="@+id/action_menu1" android:icon="@android:drawable/ic_menu_preferences" android:title="menu setting" /> <item android:id="@+id/action_menu2" android:icon="@android:drawable/ic_menu_help" android:title="help" /> </menu> </item> 
+6
source

If you want to add another icon instead of 3 dots, just create menu.xml as shown below:

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/menu_item_add" android:title="Add" app:showAsAction="always" android:icon="@drawable/ic_add" /> </menu> 

Note: Do not use android:showAsAction . Use app:showAsAction .

+6
source

For those using Kotlin:

 toolbar.overflowIcon = ContextCompat.getDrawable(applicationContext,android.R.drawable.ic_dialog_info) 

Note: "ic_dialog_info" is an example of an icon.

0
source

hope this helps you, just set your XML menu as follows:

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:icon="@drawable/your_icon" android:title="menu" app:showAsAction="always"> <menu> <item android:id="@+id/action_menu1" android:orderInCategory="1" android:title="menu 1" /> <item android:id="@+id/action_menu2" android:orderInCategory="2" android:title="menu 2" /> </menu> </item> </menu> 
0
source

Source: https://habr.com/ru/post/987300/


All Articles