我想在按下状态下更改backbutton和overflowmenu按钮的背景颜色。 我正在使用ActionBarActivity。 Appcompact v7库。 以编程方式是否可以更改后退按钮和overflowmenubutton的背景颜色?
以下是我的风格:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- <item name="windowActionBar">false</item> -->
</style>
<style name="ActionBar.Solid.Sri" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">@drawable/ab_solid_sri</item>
<item name="backgroundStacked">@drawable/ab_stacked_solid_sri</item>
<item name="backgroundSplit">@drawable/ab_bottom_solid_sri</item>
<item name="progressBarStyle">@style/ProgressBar</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarDivider">@color/action_bar_text_color</item>
<item name="actionBarDivider">@color/action_bar_text_color</item>
<item name="actionBarItemBackground">@drawable/selectable_background_sri</item>
<item name="android:actionBarStyle">@style/ActionBar.Transparent</item>
<item name="actionBarStyle">@style/ActionBar.Transparent</item>
<!--
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
-->
<item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
<item name="popupMenuStyle">@style/PopupMenu</item>
<item name="dropDownListViewStyle">@style/DropDownListView</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView</item>
<item name="actionModeBackground">@drawable/cab_background_top_sri</item>
<item name="actionModeSplitBackground">@drawable/cab_background_bottom_sri</item>
<item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode</item>
<!--
<item name="actionOverflowButtonStyle">@style/OverFlowStyle</item>
<item name="android:actionOverflowButtonStyle">@style/OverFlowStyle</item>
-->
<item name="actionDropDownStyle">@style/DropDownNav</item>
<item name="android:actionDropDownStyle">@style/DropDownNav</item>
<item name="android:actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="actionBarTabStyle">@style/ActionBarTabStyle</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
<!-- <item name="actionBarStyle">@style/Theme.MyApp.ActionBar</item> -->
</style>
<style name="ActionButton.CloseMode" parent="@style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">@drawable/btn_cab_done_sri</item>
</style>
<style name="DropDownListView" parent="@style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">@drawable/selectable_background_sri</item>
</style>
<style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_sri</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">@style/TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">@style/TitleTextStyle</item>
</style>
<style name="ActionBar.Transparent" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="background">@drawable/ab_transparent_sri</item>
<item name="progressBarStyle">@style/ProgressBar</item>
<item name="android:titleTextStyle">@style/TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">@style/TitleTextStyle</item>
</style>
<style name="ProgressBar" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">@drawable/progress_horizontal_sri</item>
</style>
<style name="OverFlowStyle" parent="@style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">@drawable/ic_empty</item>
</style>
<style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/action_bar_text_color</item>
</style>
<style name="TabTextStyle" parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/action_bar_text_color</item>
</style>
<style name="ActionBarTabStyle" parent="@style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator_ab_sri</item>
<item name="background">@drawable/tab_indicator_ab_sri</item>
</style>
<style name="DropDownNav" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">@drawable/spinner_background_ab_sri</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_sri</item>
<item name="android:dropDownSelector">@drawable/selectable_background_sri</item>
<item name="background">@drawable/spinner_background_ab_sri</item>
</style>
<!--
<style name="Theme.MyApp.ActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
remove shadow below action bar
<item name="android:elevation">0dp</item>
Support library compatibility
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">@null</item>
</style>
-->
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
<!-- Required for Lollipop. -->
<!-- <item name="android:overlapAnchor">false</item> -->
</style>
<style name="ProgressBarStyle" parent="@android:style/Widget.ProgressBar.Horizontal" />
<!--
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@drawable/actionbar_background</item>
<item name="android:windowActionBarOverlay">true</item>
Support library compatibility
<item name="background">@drawable/actionbar_background</item>
<item name="windowActionBarOverlay">true</item>
</style>
-->
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Sri.Widget" parent="@style/Theme.AppCompat">
<item name="popupMenuStyle">@style/PopupMenu</item>
<item name="dropDownListViewStyle">@style/DropDownListView</item>
</style>
</resources>
请帮帮我。谢谢你们。
答案 0 :(得分:0)
Action Bar Style Generator非常有用,但它会生成大量文件,如果您只想更改背景颜色,大部分文件都无关紧要请查看: https://stackoverflow.com/a/20077381/611258
虽然我强烈建议您使用新的toolbar或其support library equivalent.