How to change three dots button on android to other button

后端 未结 6 2070
天涯浪人
天涯浪人 2020-12-06 01:15

I wanna change the three dots button on Android to other button which is an \"Add\" button. How to do it? I have changed set the button in my drawable, but it keep prompt th

相关标签:
6条回答
  • 2020-12-06 01:46

    For those who use Kotlin:

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

    Note: "ic_dialog_info" is an icon example.

    0 讨论(0)
  • 2020-12-06 01:48

    If you want to add other icon instead of 3 dots then just create menu.xml like below code:

    <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: Don't use android:showAsAction. Use app:showAsAction.

    0 讨论(0)
  • 2020-12-06 01:54

    hope this help u, just set your xml menu like this:

    <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 讨论(0)
  • 2020-12-06 01:57

    Sorry I don't have enough reputation to post a comment. Here is the best answer I found, its one line of code:

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

    The link for the original answer is here: https://stackoverflow.com/a/35790470/4575772

    0 讨论(0)
  • 2020-12-06 02:02
    //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>
    
    0 讨论(0)
  • 2020-12-06 02:11

    Sorry i can't reply as a comment, but i'm guessing you want to change the actionbar 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 post: How to change option menu icon in the action bar?

    0 讨论(0)
提交回复
热议问题