1

I'm using Android 5 (emulator) for testing my application, but I don't know why the status bar color won't change.

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:

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:

<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...

Mark
  • 55
  • 1
  • 6
  • is it also added in android manifest file? – Abhishek Sep 09 '15 at 10:39
  • Do you see black status bar in emulator or preview in xml layout file? Because this is a difference. – Damian Kozlak Sep 09 '15 at 10:40
  • @abhishek yes, in the application block there is: "android:theme="@style/AppTheme". More information: compileSdkVersion is 23, buildToolsVersion is "23.0.1", minSdkVersion is 9, targetSdkVersion is 23 and appcompat version is 7:23.0.1. – Mark Sep 09 '15 at 10:44
  • @DamianKozlak I see correct color (#8ef8ef) in preview, but it is black in emulator. – Mark Sep 09 '15 at 10:45
  • Deleted my answer. That was incorrect :( – Pankaj Kumar Sep 09 '15 at 12:21
  • @PankajKumar so is it a bug? – Mark Sep 09 '15 at 12:24
  • No you can try with java code. There are many SO entries that uses java code to change status bar color. like http://stackoverflow.com/questions/22192291/how-to-change-the-status-bar-color-in-android or http://stackoverflow.com/questions/27093287/how-to-change-status-bar-color-to-match-app-in-lollipop-android – Pankaj Kumar Sep 09 '15 at 13:42
  • I don't think changing status bar color with java code is a clear soluton... – Mark Sep 09 '15 at 14:14

3 Answers3

1

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). if you are using device or emulator below version of 21.

Pitty
  • 1,907
  • 5
  • 16
  • 34
  • your changes should not be in style(v23). do this in style.xml – Pitty Sep 09 '15 at 13:14
  • It's not in style(v21). I'm suspecting it's a android emulator bug. Can someone test both in emulator and real device please? – Mark Sep 09 '15 at 13:20
0

On API 22 (SGS6) it works correctly. Your problem may be cause of the following BUG. Did you try update your system images for API 21 and API 22?

Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
-1

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">
Cheerag
  • 415
  • 3
  • 10