2016-07-23 87 views
0

我在我的应用程序中有两种样式(style.xml文件)。这是我写的代码。我的Android应用程序中的style.xml文件存在一些错误

<resources> 

<!-- Base application theme. --> 
<style name="Splash.Custom" parent="android:style/Theme.DeviceDefault.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
</style> 

<style name="Custom" parent="android:style/Theme.Holo.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
</style> 

我得到一些错误,在日志中。我也点了一张照片。

enter image description here

而且我希望有一个暗(黑色)行动起来吧......所以我不知道该怎么办

回答

0

请使用以下风格

<style name="Splash.Custom" parent="Theme.AppCompat.Light.NoActionBar"> 
<!-- Customize your theme here. --> 
<item name="colorPrimary">@color/colorPrimary</item> 
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
</style> 

<style name="Custom" parent="Theme.AppCompat.Light.DarkActionBar"> 
<item name="colorPrimary">@color/colorPrimary</item> 
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> 

编辑代码

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:minHeight="?attr/actionBarSize" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:titleTextColor="@android:color/white" 
    android:background="?attr/colorPrimary"> 
</android.support.v7.widget.Toolbar> 
+0

如果我需要黑色动作栏,我该怎么办? –

+1

更改颜色主要代码的颜色.xml文件 – vinoth12594

+0

如果答案是帮助完整投出投票 – vinoth12594

0

我想你使用AppCompatActivity,所以一切都清楚,你需要使用程序兼容性的主题,所以更改请

<style name="Splash.Custom" parent="android:style/Theme.DeviceDefault.Light.NoActionBar"> 
<style name="Custom" parent="android:style/Theme.Holo.Light.DarkActionBar"> 

<style name="Splash.Custom" parent="Theme.AppCompat.Light.NoActionBar"> 
<style name="Custom" parent="Theme.AppCompat.Light.DarkActionBar"> 

或者,如果您希望AppCompat上的主题不是changin,那么您可以从其他活动扩展。

修订

,如果你想改变你的动作条的颜色此信息。

如果您使用SDK级别> = 21,那么你需要提供属性colorPrimarycolorPrimaryDark在你的主题:

<item name="colorPrimary">@color/my_awesome_red</item> 
<item name="colorPrimaryDark">@color/my_awesome_darker_red</item> 

如果你的SDK级别< 21,那么我建议你来更新它:),或写是这样的:如果你正在扩大与AppCompatActivity主屏幕的活动将其更改为活动

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="android:background" tools:ignore="NewApi">@color/red</item> 
    <item name="background">@color/red</item> 
</style> 

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light"> 
    <item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item> 
    <item name="actionBarStyle">@style/MyActionBar</item> 

</style> 
+0

我想要一个黑色的动作栏....你的代码给了我一个白色的动作栏! –

+0

正如我所说,你不能改变你的风格,但只是扩展而不是从AppCompatActivity,因为没有办法从AppCompatActivity扩展,并提供不Theme.AppCompat。另外我会更新我对动作栏颜色的回答,请检查 –

0

或更改主题Theme.AppCompat.Light.NoActionBar

0

使用1)Theme.AppCompat.Light.NoActionBar

2)Theme.AppCompat.Light.DarkActionBar

相关问题