更改操作栏中的溢出图标

是否可以更改操作栏中的溢出图标? 我有所有的ActionBar项目的蓝色图标,我也想改变溢出图标,当它出现。

你可以用一个样式,但是你必须把它添加到主要的主题声明中。

<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> 

你也可以dynamic地改变它,我在这里详细介绍一下:

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

对于那些不能工作的人,不要使用“android:”命名空间。

 <item name="actionOverflowButtonStyle">@style/OverFlow</item> 
  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> 
  2. 将自定义主题“MyTheme”放在AndroidManifest.xml的应用程序标签中

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

玩的开心。@。@

@ adneal的答案是正确的(所以这只是一个社区维基解释来展开)。

其中一条评论提示,可能会误解如何做到这一点,所以我的回答是关于如何覆盖溢出图标图像的另一个例子。

以下代码基于ADT示例New Android Project中的模板样式。 代码来自res/values文件夹中的styles.xml文件。


 <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- 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/OverflowMenuButton</item> </style> <style name="OverflowMenuButton" parent="@android:style/Widget.Holo.ActionButton.Overflow"> <item name="android:src">@drawable/ic_menu_moreoverflow</item> </style> 

上面的代码所做的是使用名为ic_menu_moreoverflow任何drawable来replace默认溢出图标。 如果你想快速testing一下,使用你的应用程序的启动器图标文件名,这将使它明白它是如何工作的。

尝试理解ActionBar样式时使用的有用资源是:

  • Android操作栏样式生成器

在那里你可以定义特定的颜色用于Overflow图标,ZIP文件将包含正确的styles.xml文件。

经过漫长的search,我得到了如下的指导:

  1. 检查宣言文件中的主题。
  2. 然后去res-> values->主题。
  3. 在这个文件中find主题名称。
  4. 在theme.xml中添加主题中的项目:

     <item name="android:actionBarWidgetTheme">@style/widgetStyle</item> <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item> 
  5. 在同一个文件中添加样式中的图标我的意思是theme.xml:

     <style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow"> <item name="android:src">@drawable/icon_menu</item> </style> 
  6. 查看您想要更改的自定义图标

它为我工作