简体   繁体   English

状态栏颜色不会随着AppCompatActivity更改

[英]Status bar color won't change with AppCompatActivity

I'm using Android 5 (emulator) for testing my application, but I don't know why the status bar color won't change. 我正在使用Android 5(仿真器)来测试我的应用程序,但我不知道为什么状态栏颜色不会改变。

styles.xml: 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>

Java: Java的:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Activity.xml: 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>

Tested also on Android 6 (emulator), Toolbar is #0000ff but status bar is still black... 工具栏也已在Android 6(仿真器)上进行了测试,为#0000ff但状态栏仍为黑色...

I am not sure but it may be problem regarding to your emulator or device 我不确定,但这可能与您的仿真器或设备有关

please confirm that your AppTheme style is not in style(v21). 请确认您的AppTheme样式不是样式(v21)。 if you are using device or emulator below version of 21. 如果您使用的设备或仿真器版本低于21。

On API 22 (SGS6) it works correctly. 在API 22(SGS6)上,它可以正常工作。 Your problem may be cause of the following BUG . 您的问题可能是以下BUG的原因。 Did you try update your system images for API 21 and API 22? 您是否尝试过为API 21和API 22更新系统映像?

Use below code for style 使用以下代码作为样式

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

</style>

Also dont forgot to give style in your manifest file application tag. 也不要忘记在清单文件应用程序标记中提供样式。

android:theme="@style/AppTheme">

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

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