更改操作栏溢出图标

时间:2014-01-23 06:27:01

标签: android android-actionbar

我在values-v11文件夹

中应用了以下代码

styles.xml

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

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

但它没有改变溢出图标,这个主题中的所有其他项目都运行正常,但不是这个,我错过了什么?

3 个答案:

答案 0 :(得分:10)

 i want to apply these styles above 4.0 version 

但是你有values-v11

中的样式

另请注意

parent="android:Theme.Holo.Light" // in your code

parent="@android:style/Theme.Holo" // mine

应该在values-v14

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="MyTheme" parent="@android:style/Theme.Holo">
        <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
    </style>
    <style name="MyActionButtonOverflow" parent="@android:style/Widget.Holo.Light.ActionButton.Overflow">
       <item name="android:src">@drawable/ic_launcher</item>    
    </style>
</resources>
Snap

忘记ui用于测试的样子。但是您会将启动器图标视为溢出菜单图标。

enter image description here

编辑:

这是我的测试样本

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
             <item name="android:actionBarStyle">@style/MyActionBar</item>
              <item name="android:actionBarDivider">@color/red</item>
              <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
         <item name="android:background">#FF9D21</item>

         <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
    </style> 
    <style name="MyActionBarTitleText"
           parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
        <item name="android:textStyle">bold</item>
    </style>
      <style name="MyActionButtonOverflow" parent="@android:style/Widget.Holo.Light.ActionButton.Overflow">
    <item name="android:src">@drawable/launcher</item>    
    </style>
    <style name="ActionButton" parent="@android:style/Widget.Holo.Light.ActionButton">
</style>
</resources>

Colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="red">#FF0000</color>
</resources>

对齐

enter image description here

答案 1 :(得分:1)

我认为您应该执行以下操作:

<style name="MyCustomTheme" parent="style/Theme.Holo">
    <item name="android:actionOverflowButtonStyle">@style/MyCustomTheme.OverFlow</item>
</style>

<style name="MyCustomTheme.OverFlow">
    <item name="android:src">@drawable/my_overflow_image</item>
</style>

答案 2 :(得分:0)

您可以像下面这样用Java编程设置它:

toolbar.setOverflowIcon(getResources().getDrawable(R.drawable.your_icon, null));