Java 如何更改操作栏及其over flow菜单的颜色?
以下是我的应用程序的屏幕截图: 我可以使用R.id.button1访问按钮,并使用Java 如何更改操作栏及其over flow菜单的颜色?,java,android,user-interface,Java,Android,User Interface,以下是我的应用程序的屏幕截图: 我可以使用R.id.button1访问按钮,并使用 case R.id.lightgreen: for (Button currentButton : buttons) { currentButton.setBackgroundResource(R.drawable.lightgreen); } 有没有办法访问操作栏及其溢出菜单,以同样的方式设置它们的颜色 [编辑] ActionBar
case R.id.lightgreen:
for (Button currentButton : buttons) {
currentButton.setBackgroundResource(R.drawable.lightgreen);
}
有没有办法访问操作栏及其溢出菜单,以同样的方式设置它们的颜色
[编辑]
ActionBar actnbar;
actnbar.setBackgroundDrawable(R.drawable.blue_button);
要求将blue_按钮转换为drawable时出现错误,但如果这样做,则无法设置按钮。在项目的“值”文件夹中定义自定义样式.xml,如下所示:
<resources>
<style name="Theme.CustomTHeme" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/Theme.CustomTHeme.ActionBar</item>
</style>
<style name="Theme.CustomTHeme.ActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="background">@drawable/header_gradient</item>
<item name="titleTextStyle">@style/Theme.CustomTHeme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.CustomTHeme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#fff</item>
</style>
</resources>
@style/Theme.CustomTHeme.ActionBar
@可拉深/割台坡度
@style/Theme.CustomTHeme.ActionBar.TitleTextStyle
#fff
然后在您的AndroidManifest.xml中:
<application
android:name=".App"
android:label="@string/app_name"
android:icon="@drawable/logo"
android:theme="@style/Theme.CustomTHeme">
...
...
您还必须注意支持其他api-s(其他值文件夹)
如果您正在使用actionbarcompat支持库,您可以在活动中访问actionbar,该活动使用getSupportActionBar()
扩展了ActionBarActivity
,并使用
setStackedBackgroundDrawable()
或setBackgroundDrawable()
或相应的getActionBar()方法(如果不使用支持库)。是设置动作栏样式的绝佳工具 您可以使用ActionBar.setBackgroundDrawable()
更改ActionBar
背景。我还需要写些什么,因为只写ActionBar.setBackgroundDrawable()会出错。ActionBar.setBackgroundColor(新的ColorDrawable(必选颜色))代码>…我正在编辑我的问题。这是我最初使用的,但是我无法为按钮设置自定义背景。如果您得到一个,会出现什么错误?你说按钮是什么意思,它们不在actionbar之类的菜单中?你能把代码调试到那一行看看会发生什么吗?最初我使用的是动作条样式生成器,它生成了一个像你上面所说的主题,然后每当我尝试使用“@style/Widget.AppCompat.buttons”更改按钮样式时,我都会出错。如果我使用动作条样式生成器创建主题,然后我不知道如何在我的应用程序中设计我的按钮,即1、2、3等。