在android.support.v7.app.ActionBar中更改背景颜色
我对我的项目做了一些更改,比如添加了在android.support.v7.app.ActionBar中更改背景颜色,android,xml,android-actionbar,android-actionbar-compat,Android,Xml,Android Actionbar,Android Actionbar Compat,我对我的项目做了一些更改,比如添加了android.support.v7.app.actionBarDrawertogle/ActionBar/ActionBarActivity/Toolbar。一切正常,唯一的问题是我不知道如何更改ActionBar背景色,它是灰色的,文本是黑色的。 这就是我所尝试的: themes.xml <resources> <!-- the theme applied to the application or activity -->
android.support.v7.app.actionBarDrawertogle/ActionBar/ActionBarActivity/Toolbar
。一切正常,唯一的问题是我不知道如何更改ActionBar
背景色,它是灰色的,文本是黑色的。
这就是我所尝试的:
themes.xml
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme1" parent="@style/Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/blue</item>
<item name="background">@color/blue</item>
</style>
</resources>
<application
android:allowBackup="true"
android:icon="@drawable/zenyt"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme1">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
但我得到了这个错误:
Caused by: java.lang.NullPointerException
at com.zenyt.MainActivity.onCreate(MainActivity.java:67)
第67行是这一行:bar.setBackgroundDrawable(newColorDrawable(Color.parseColor(“#FF2E4976”))代码>
另一种方式是:
<item name=”colorPrimary”>@color/my_awesome_red</item>
<item name=”colorPrimaryDark”>@color/my_awesome_darker_red</item>
对不起,我说的是英语。在strings.xml中使用颜色定义颜色
<color name="blue">#FF2E4976</color>
#FF2E4976
然后
@颜色/蓝色
@颜色/蓝色
这样做了,但没有效果,操作栏仍然是灰色的。等等,您是否将windowActionBar设置为false,因为您使用工具栏作为操作栏?可能与此类似
<item name=”colorPrimary”>@color/my_awesome_red</item>
<item name=”colorPrimaryDark”>@color/my_awesome_darker_red</item>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
<color name="blue">#FF2E4976</color>
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/blue</item>
<item name="background">@color/blue</item>
</style>