Android 状态栏和操作栏背景的颜色不变

Android 状态栏和操作栏背景的颜色不变,android,Android,我目前正在我的代码中实现工具栏,但有一些问题。它不会显示或更改状态栏和背景的颜色。以下是我编写的代码: toolbar.xml 结果 我能知道我做错了什么吗?谢谢..首先,在工具栏布局XML文件中,您没有将样式链接到视图。尝试添加以下行: style="@style/AppTheme.NoActionBar" 即: 以及样式XML文件: <resources> <!-- Application theme. --> <style name=

我目前正在我的代码中实现工具栏,但有一些问题。它不会显示或更改状态栏和背景的颜色。以下是我编写的代码:

toolbar.xml 结果
我能知道我做错了什么吗?谢谢..

首先,在工具栏布局XML文件中,您没有将样式链接到视图。尝试添加以下行:

style="@style/AppTheme.NoActionBar"
即:


以及样式XML文件:

<resources>

    <!-- Application theme. -->
    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light">

        <item name="windowActionBar">false</item>
        <item name="android:background">@color/blue</item>

    </style>

    <color name="blue">#3F51B5 </color>

</resources>

假的
@颜色/蓝色
#3F51B5

尝试过,但结果相同。您是否尝试将静态颜色设置为背景颜色,但背景颜色不变?或者颜色会因某些事件而改变?@DanKCl我对代码做了一些更改,请立即尝试。它为工具栏视图提供静态蓝色背景。
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_warfarin_info);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }
}
style="@style/AppTheme.NoActionBar"
<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_awesome_toolbar"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:minHeight="?attr/actionBarSize"
    style="@style/AppTheme.NoActionBar"
    >
<resources>

    <!-- Application theme. -->
    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light">

        <item name="windowActionBar">false</item>
        <item name="android:background">@color/blue</item>

    </style>

    <color name="blue">#3F51B5 </color>

</resources>