Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 按下时更改actionbar按钮的背景色_Android_Button_Colors_Background_Android Actionbar - Fatal编程技术网

Android 按下时更改actionbar按钮的背景色

Android 按下时更改actionbar按钮的背景色,android,button,colors,background,android-actionbar,Android,Button,Colors,Background,Android Actionbar,如果我按下动作栏上的按钮,那么它的背景色就不是我想要的。我的项目的背景色不响应我的单击事件。按下时,如何更改此属性和背景色?您需要声明属性,该属性是: 自定义项状态列表操作栏项的可绘制背景 然后,在您的样式中执行以下操作: <style name="CustomStyle" parent="@style/Theme.Holo.Light" > <item name="android:actionBarItemBackground">@drawable/ab_ite

如果我按下动作栏上的按钮,那么它的背景色就不是我想要的。我的项目的背景色不响应我的单击事件。按下时,如何更改此属性和背景色?

您需要声明属性,该属性是:

自定义项状态列表操作栏项的可绘制背景

然后,在您的样式中执行以下操作:

<style name="CustomStyle" parent="@style/Theme.Holo.Light" >
    <item name="android:actionBarItemBackground">@drawable/ab_item_background</item>
    <item name="actionBarItemBackground">@drawable/ab_item_background</item>
</style>  
在中,您可以找到所有可能的自定义项以及执行此操作的所有属性

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0a0a0a")));

这可能有助于

通过使用DarkActionBar来修复它,非常好地工作,谢谢。。不过有一件事是安卓可以理解的,
android:actionBarItemBackground
,而
actionBarItemBackground
给出了错误,所以我把它删除了,这两个都有必要吗?这取决于你的actionbar@RohanKandwal。如果您使用SherlockAB或支持库,您必须使用它,是的。@Fllo我使用支持库,正如我所说,
actionBarItemBackground
在编译时出错,所以我将其删除。在这种情况下,我如何同时使用这两种语言。我看到@RohanKandwal。当您在style.xml中编写这些属性时,您必须关闭此文件,清理并保存项目。这是更改actionbar的背景色,而不是home按钮。您需要自定义actionbar。查看这两个链接我想你也需要这个链接:
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0a0a0a")));