更改操作栏中的溢出图标

pja*_*cze 110 android android-3.0-honeycomb android-4.0-ice-cream-sandwich android-actionbar

是否可以更改操作栏中的溢出图标?我有所有ActionBar项目的蓝色图标,我还想在出现时更改溢出图标.

adn*_*eal 253

您可以使用样式,但必须将其添加到主要主题声明中.

<resources>
    <!-- Base application theme. -->
    <style name="Your.Theme" parent="@android:style/Theme.Holo">
        <!-- Pointer to Overflow style ***MUST*** go here or it will not work -->
        <item name="android:actionOverflowButtonStyle">@style/OverFlow</item>
    </style>

    <!-- Styles -->
    <style name="OverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_action_overflow</item>
    </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

你也可以动态地改变它,我在这里详细介绍:

以编程方式更改Android Overflow菜单图标

  • 对于ActionBarSherlock用户,父样式是:`parent ="Widget.Sherlock.ActionButton.Overflow"` (10认同)
  • 对于appcompat(无论如何都是v21棒棒糖),`parent ="@ style/Widget.AppCompat.ActionButton.Overflow"`似乎对我有用. (7认同)
  • 请注意,这适用于主题,而不是STYLE.让我坚持一段时间直到我意识到这一点.谢谢@aneal (6认同)
  • 这将在运行Android 3.0(API 11)的平板电脑上崩溃,因为它不喜欢定义样式"android:actionOverflowButtonStyle"的人(可能是平台错误).因此,您必须在values-v11/styles.xml和values-v15/styles.xml中使用不同的样式. (5认同)

use*_*401 16

对于那些无法让它工作的人尝试这个没有"android:"命名空间.

<item name="actionOverflowButtonStyle">@style/OverFlow</item>
Run Code Online (Sandbox Code Playgroud)

  • @DaMachk如果你正在使用AppCompat,那么不要包含"android:"命名空间. (4认同)

Lun*_*ong 5

  1. 在styles.xml 中更改Actionbar 的自定义溢出图标。

     <resources>
        <!-- Base application theme. -->
        <style name=“MyTheme" parent="@android:style/Theme.Holo">
           <!-- Pointer to Overflow style DONT forget! -->
           <item name="android:actionOverflowButtonStyle">@style/MyOverFlow</item>
        </style>
    
        <!-- Styles -->
        <style name="MyOverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
            <item name="android:src">@drawable/ic_your_action_overflow</item>
        </style>
     </resources>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将自定义主题“MyTheme”放在 AndroidManifest.xml 的应用程序标签中

    <application
        android:name="com.example.android.MainApp"
        android:theme="@style/AppTheme">
    </application>
    
    Run Code Online (Sandbox Code Playgroud)

玩得开心。@。@


Sta*_*ave 5

无论我尝试做什么styles.xml,没有一个解决方案对我有用。最后,如果您有 AppCompat 23+(您应该这样做),这是实际有效的最简单方法:

toolbar.setOverflowIcon(drawable);
Run Code Online (Sandbox Code Playgroud)