Java 状态栏颜色赢得';不随活动而改变

Java 状态栏颜色赢得';不随活动而改变,java,android,xml,Java,Android,Xml,我正在使用Android 5(emulator)测试我的应用程序,但我不知道为什么状态栏的颜色不会改变 styles.xml: <resources> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">#0000ff</item> <item name="colorPrimaryDark

我正在使用Android 5(emulator)测试我的应用程序,但我不知道为什么状态栏的颜色不会改变

styles.xml:

<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#0000ff</item>
    <item name="colorPrimaryDark">#8ef8ef</item>
    <item name="colorAccent">#000fff</item>
    <item name="android:statusBarColor">#8ef8ef</item>
</style>

</resources>
Activity.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>


同样在Android 6(emulator)上测试,工具栏是
#0000ff
,但状态栏仍然是黑色的

使用下面的代码作为样式

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:colorPrimary">@color/red4</item>
    <item name="android:colorPrimaryDark">@color/red10</item>

</style>

使用下面的代码作为样式

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:colorPrimary">@color/red4</item>
    <item name="android:colorPrimaryDark">@color/red10</item>

</style>

我不确定,但这可能是关于您的模拟器或设备的问题


请确认您的AppTheme样式不在样式(v21)中。如果您使用的是低于21版本的设备或模拟器

我不确定,但您的模拟器或设备可能有问题


请确认您的AppTheme样式不在样式(v21)中。如果您使用的是低于21版本的设备或模拟器

在API 22(SGS6)上,它工作正常。您的问题可能是以下原因造成的。您是否尝试更新API 21和API 22的系统映像?

在API 22(SGS6)上,它工作正常。您的问题可能是以下原因造成的。您是否尝试更新API 21和API 22的系统映像?

是否也添加到android清单文件中?是否在emulator中看到黑色状态栏或在xml布局文件中看到预览?因为这是一个区别。@abhishek是的,在应用程序块中有:“android:theme=“@style/AppTheme”。更多信息:compileSdkVersion是23,buildToolsVersion是“23.0.1”,minSdkVersion是9,targetSdkVersion是23,appcompat版本是7:23.0.1。@DamianKozlak我看到了正确的颜色(#8ef8ef)在预览中,但在emulator中是黑色的。删除了我的答案。这是不正确的:(它也添加在android清单文件中吗?你在emulator中看到黑色状态栏还是在xml布局文件中看到预览?因为这是一个区别。@abhishek是的,在应用程序块中有:“android:theme=“@style/AppTheme”。更多信息:compileSdkVersion是23,buildToolsVersion是“23.0.1”,minSdkVersion是9,targetSdkVersion是23,appcompat版本是7:23.0.1。@DamianKozlak我在预览中看到了正确的颜色(#8ef8ef),但在emulator中它是黑色的。删除了我的答案。那是不正确的:(扩展
Activity
而不是
AppCompatActivity
不是个好主意。扩展
Activity
而不是
AppCompatActivity
不是个好主意。您的更改不应采用样式(v23)。在样式中执行此操作。xmlIt不采用样式(v21)。我怀疑这是一个android仿真器错误。有人可以在仿真器和真实设备中测试吗?您的更改不应该是样式(v23)。请用样式执行此操作。xmlIt不是样式(v21)。我怀疑这是一个android仿真器错误。有人可以在仿真器和真实设备中测试吗?
android:theme="@style/AppTheme">