我想使用不同的ActionBar
圖標取決於我使用的風格(黑色或淺色)。 我無法弄清楚如何,繼承人是我的嘗試:更改ActionBar菜單圖標取決於風格
<style name="AppThemeDark" parent="Theme.Sherlock.ForceOverflow">
<item name="android:actionButtonStyle">@style/customActionButtonStyleDark</item>
<item name="actionButtonStyle">@style/customActionButtonStyleDark</item>
</style>
<style name="AppThemeLight" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:actionButtonStyle">@style/customActionButtonStyleLight</item>
<item name="actionButtonStyle">@style/customActionButtonStyleLight</item>
</style>
<style name="customActionButtonStyleDark" >
<item name="@drawable/action_search">@drawable/action_search</item>
</style>
<style name="customActionButtonStyleLight" >
<item name="@drawable/action_search">@drawable/action_search_light</item>
</style>
我也試過直接插入<item name="@drawable/action_search">@drawable/action_search</item>
進入主題風格,但毫無效果。
任何想法如何?
這是工作的罰款,感謝的!但是如何從Java中使用它?當我調用menuLetters.setIcon(R.attr.ic_action_messages);我收到錯誤,找不到資源。 – BArtWell
好問題,我想答案是[這裏](http://stackoverflow.com/questions/8793183/access-resource-defined-in-theme-and-attrs-xml-android)。這個技巧似乎是,你必須告訴Android目前設置了什麼主題,所以它知道要獲取哪種風格的資源。 –
是的,你說得對,它也能正常工作。謝謝! – BArtWell