简体   繁体   English

Android操作栏自定义颜色的样式

[英]Android action bar custom color in styles

I've tried to change the color of the action bar in 100 ways, but it's still the same. 我试图以100种方式更改操作栏的颜色,但是仍然相同。 Here is my code: 这是我的代码:

<resources>

<!-- Base application theme. -->

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:statusBarColor">#00B0FF</item>
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#ffffff</item>
</style>

Can someone explain me where is my mistake? 有人可以向我解释我的错误在哪里吗?

Try this: 尝试这个:

<resources>

<!-- Base application theme. -->

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="android:statusBarColor">#00B0FF</item>
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#ffffff</item>
</style>

If you are extends material design api 21 => take a look 如果您是扩展Material Design API 21 => 看看

<resources>
    <!-- inherit from the material theme -->
    <style name="AppTheme" parent="android:Theme.Material">
      <!-- Main theme colors -->
      <!--   your app branding color for the app bar -->
      <item name="android:colorPrimary">@color/primary</item>
      <!--   darker variant for the status bar and contextual app bars -->
      <item name="android:colorPrimaryDark">@color/primary_dark</item>
      <!--   theme UI controls like checkboxes and text fields -->
      <item name="android:colorAccent">@color/accent</item>
    </style>
</resources>

But if you are extends AppCompat => take a look 但是,如果您扩展了AppCompat =>, 请看一下

<resources>
    <!-- inherit from App Compat theme -->
    <style name="AppTheme" parent="Theme.AppCompat.Light"">
      <!-- Main theme colors -->
      <!--   your app branding color for the app bar -->
      <item name="colorPrimary">@color/primary</item>
      <!--   darker variant for the status bar and contextual app bars -->
      <item name="colorPrimaryDark">@color/primary_dark</item>
      <!--   theme UI controls like checkboxes and text fields -->
      <item name="colorAccent">@color/accent</item>
    </style>
</resources>

We now use the support implementation of Toolbar/ActionBar on all platforms meaning that we no longer read any android: attributes related to the action bar. 现在,我们在所有平台上使用Toolbar / ActionBar的支持实现,这意味着我们不再阅读任何与操作栏相关的android:属性。 Chris Banes 克里斯·巴尼斯

please try this code in value-v14 and also select theme as myAppTheme In Munifest.xml 请在value-v14中尝试此代码,并在Munifest.xml中选择主题作为myAppTheme

 <style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">

    <item name="android:background">@color/color1</item>
    <item name="android:backgroundStacked">@color/color1</item>
    <item name="android:backgroundSplit">@color/color1</item>
    <item name="android:statusBarColor">@color/staus_bar_color</item>
 </style>
 <style name="myAppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
  </style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM