在 Appcompat 21 中更改工具欄顏色 - Change Toolbar color in Appcompat 21

問題:

I am testing out the new Appcompat 21 Material Design features.我正在測試新的 Appcompat 21 Material Design 功能。 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.並將其包含在我的主佈局文件中。

Then I've set it as supportActionBar like that:然後我將它設置爲 supportActionBar 像這樣:

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?我應該如何更改背景和文本顏色?

I've gone through this instructions:我已經完成了這個說明:

http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html http://android-developers.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>

EDIT :編輯

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:我更喜歡白色文本和白色菜單按鈕,而不是黑色文本和黑色菜單按鈕:

在此處輸入圖片說明


解決方案:

參考: https://stackoom.com/en/question/1nQAO
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章