如何更改Android溢出菜单图标

20

如何更改操作栏右侧溢出菜单中的图标,如下图所示?我的Holo主题默认指定了这个三行黑色堆叠图标,但我想要其他的图标。我似乎找不到解决方案。我查看了关于http://developer.android.com/guide/topics/ui/menus.html的文档,但它并没有提供太多帮助。

谢谢!

"ActionBar"


请不要动那个图标。用户经常攻击那些不遵循基本平台规范的开发者。除非你能积极证明,如果你不改变那个图标,你的用户将拒绝你的应用程序,请不要动那个图标。话虽如此,我也不知道那个图标在哪里可以更改。 - CommonsWare
2
我想改变那个图标的唯一原因是将它变成白色而不是黑色。我的操作栏背景在那个区域非常暗,几乎看不到图标。我没有改变平台惯例或做任何戏剧性的事情 :) - newdev
啊,抱歉,我反应过度了。人们会认为在控制栏样式的任何地方都可以更改该图标。我没有在SDK中看到该图标,因此我没有搜索字符串来尝试在styles.xml或kin中找到它。 - CommonsWare
谷歌员工,请查看此答案:https://dev59.com/k18d5IYBdhLWcg3w6luM#35790470 - Atul
8个回答

31

你可以尝试像这样:

<style name="MyTheme" parent="android:style/Theme.Holo.Light">
     <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
</style>

<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
    <item name="android:src">@drawable/my_action_bTutton_overflow</item>
</style>

同时在AndroidManifest.xml文件中进行配置

<application
    android:theme="@style/MyTheme" >

20

定义一个自定义样式:例如,我们称其为customoverflow

在此样式中,您将android:src设置为您想要使用的图片。现在创建一个父样式为Theme.holo的样式。

在此样式中,您需要定义:

<item name="android:actionOverflowButtonStyle">@style/customoverflow</item>

我刚刚测试了这个,它有效。


2
它的可定制性不够。假设您有一个浅色背景和一个深色溢出按钮。如果您选择在操作模式(CAB)中使用深色背景,则无法将溢出按钮切换为浅色。 - AlikElzin-kilaka
1
如何在Appcompat中实现这个? - Amit Tripathi

10
如果您正在使用AppCompat主题,您可以通过以下代码实现。
res/values/themes.xml
<style name="MyTheme" parent="@style/Theme.AppCompat.Light">
     <item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflow</item>

      <!-- Support library compatibility -->
     <item name="actionOverflowButtonStyle">@style/ActionButtonOverflow</item>

</style>

      <style name="ActionButtonOverflow" parent="@style/Widget.AppCompat.ActionButton.Overflow">
            <item name="android:src">@drawable/ic_launcher</item>
        </style>

并且在 androidmanifest.xml 文件中

<application
    android:theme="@style/MyTheme" >

2
非常适合指出支持库兼容性差异。 - Čikić Nenad

3
我注意到当应用程序的主题为Holo时,它会变成白色,但当主题为Holo.Light时,它会变成黑色。
然而,将操作栏的样式更改为从Holo继承,其余部分从Holo.Light继承并不能解决问题,但这应该可以指向你应该修改哪种样式。
我尝试过的是:
<style name="AppThemeLight" parent="android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:windowContentOverlay">@drawable/actionbar_shadow</item>
</style>    
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/header_brown</item>
    <item name="android:titleTextStyle">@style/ActionBarTitle</item>
    <item name="android:icon">@drawable/header</item>       
</style>

我有同样的问题,我认为这个解决方案很接近。

1
重复的问题, 如何在操作栏中更改溢出图标 以下是我的答案,
  1. Change your custom overflow icon of Actionbar in styles.xml

     <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>
    
  2. Put custom theme "MyTheme" in application tag of AndroidManifest.xml

    <application
        android:name="com.example.android.MainApp"
        android:theme="@style/AppTheme">
    </application>
    

玩得开心。@.@


0
基本上,较新的 API 级别中可用的主题自定义可以放在 res/values-vXX/styles.xml 中,而与向后兼容性相关的自定义可以放在 values/styles.xml 中。
Shalafi 的解决方案需要添加一些代码:因此将此代码添加到res/values-vXX/styles.xmlres/values/styles.xml 中,这将像魔术一样工作!
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
 <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
</style>

<style name="MyActionButtonOverflow"parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/your_overflow_icon</item>
</style>

同时在 AndroidManifest.xml 文件中添加它

<application
    android:theme="@style/AppTheme" >

0

Shalafi的解决方案可以工作,但需要进行一些更改!您需要将theme.Holo指定为主题的父级,但它的缺点是会更改默认文本颜色(至少在我的样式中)。

修改后的代码应该是:

   <style name="AppThemeLight" parent="android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:windowContentOverlay">@drawable/actionbar_shadow</item>
</style>    
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/header_brown</item>
    <item name="android:titleTextStyle">@style/ActionBarTitle</item>
    <item name="android:icon">@drawable/header</item>       
</style>

0
<style name="ToolBarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
    <item name="android:tint">@color/colorAccent</item>

创建上述主题。使用您的颜色设置色调,并将此主题添加到工具栏。

<androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ToolBarTheme"/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接