本文介绍了在Appcompat 21更改工具栏的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试了新的Appcompat 21材质设计特点。因此,我创建了一个工具栏是这样的:

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?

我通过这个说明了:

<一个href="http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-$p$p.html">http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-$p$p.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>

修改

我可以通过增加code这些线路的主题来改变背景颜色:

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>

但他们不会影响文字的颜色。我在想什么?取而代之的是黑色文本和黑色的菜单按钮,我宁愿preFER白色文字和白色菜单按钮:

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更改工具栏的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:30