在 Appcompat 21 中更改工具栏颜色 [英] Change Toolbar color in Appcompat 21
问题描述
我正在测试新的 Appcompat 21 Material Design 功能.因此我创建了一个这样的工具栏:
I am testing out the new Appcompat 21 Material Design features. Therefore I've created a Toolbar like this:
<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/activity_my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
并将其包含在我的主布局文件中.
and included it in my main layout file.
然后我将其设置为 supportActionBar:
Then I've set it as supportActionBar like that:
Toolbar toolBar = (Toolbar)findViewById(R.id.activity_my_toolbar);
setSupportActionBar(toolBar);
它正在工作,但不知何故我无法弄清楚如何自定义工具栏.它是灰色的,上面的文字是黑色的.我应该如何更改背景和文本颜色?
It's working, but somehow I can't quite figure out how to customize the toolbar. It's grey and the text on it is black. How should I change background and text color?
我已完成此说明:
http://android-developer.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html
我为了改变颜色做了哪些检查?
What have I overseen to change colors?
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowActionBar" tools:ignore="NewApi">false</item>
<item name="windowActionBar">false</item>
</style>
编辑:
我能够通过将这些代码行添加到主题来更改背景颜色:
I was able to change the background color by adding these lines of code to the theme:
<item name="colorPrimary">@color/actionbar</item>
<item name="colorPrimaryDark">@color/actionbar_dark</item>
但它们不会影响文本颜色.我错过了什么?我更喜欢白色文本和白色菜单按钮,而不是黑色文本和黑色菜单按钮:
But they won't affect the text color. What am I missing? Instead of the black text and black menu button, I'd rather prefer a white text and white menu buttons:
推荐答案
同样,这一切都在您提供的链接中
again this is all in the link you supplied
要将文本更改为白色,您只需更改主题即可.
to change the text to white all you have to do is change the theme.
使用这个主题
<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/activity_my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
这篇关于在 Appcompat 21 中更改工具栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!