![](/img/trans.png)
[英]Can't set hex color and view the icon on the action bar using Theme.AppCompat
[英]Action bar color does not change when using Theme.AppCompat
我要做的就是讓操作欄和狀態欄更改顏色以進行材質設計。 以下是我創建的主題:
<!-- Base application theme. -->
<style name="AppTheme2" parent="Theme.AppCompat">
<!-- colorPrimary is used for the default action bar background -->
<item name="android:colorPrimary">#FF5722</item>
<!--<item name="android:statusBarColor">#E64A19</item>-->
<!-- colorPrimaryDark is used for the status bar -->
<item name="android:colorPrimaryDark">#E64A19</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="android:colorAccent">#FF9800</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
</style>
但是,運行時狀態欄的顏色會很好地更改,但操作欄仍為黑色。 我知道對此可能有一個簡單的答案,但是我想念的是什么?
該問題與建議的問題不重復。 請刪除標志。
由於您使用的是AppCompat,因此應使用AppCompat屬性,而不要使用Android系統屬性。
更改
android:colorPrimary
至
colorPrimary
整個過程應如下所示:
<!-- Base application theme. -->
<style name="AppTheme2" parent="Theme.AppCompat">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#FF5722</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#E64A19</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF9800</item>
</style>
從colorPrimary
刪除android:
colorPrimary
appcompat-v7
在其主題中未使用android:
前綴,最后我檢查了一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.