ZeeRooo
ZeeRooo

Reputation: 31

Wrong color in status bar

Why my status bar have this color? I need the same color as the toolbar (blue)

enter image description here

styles.xml

<style name="MFB" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

settingsactivity.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_below="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

In the main activity its working fine, look:

enter image description here

I dont know what is wrong here... i looked for an answer in other post but same i got the white status bar :/

Thank you :) and sorry if it is a noob question

EDIT

Toolbar.xml:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

Note: im using

"com.android.support:appcompat-v7:23.4.0" 
"com.android.support:design:23.4.0"

Upvotes: 1

Views: 2291

Answers (4)

Waqas Ahmed Ansari
Waqas Ahmed Ansari

Reputation: 1699

Try removing <item name="android:statusBarColor">@android:color/transparent</item> thisline. Status bar takes color from colorPrimaryDark. Set this color to your desired one.

See this

enter image description here

EDIT

If you want to change the color of status bar at some stage in your app, you can try this

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(YOUR_COLOR);

Upvotes: 1

dipali
dipali

Reputation: 11188

<style name="MFB" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionModeOverlay">true</item>
   <item name="android:statusBarColor">@android:color/transparent</item>
</style>

change above android:statusBarColor in your style.

   <item name="android:statusBarColor">@color/blue</item>

it's working.I hope its solve your issue.

Upvotes: 1

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20990

I think the problem must be you are not creating res/values-v21 folder to your project. to give different style to Lollipop and upper device you have to create values-v21 folder in res directory and define your style there.

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppBaseTheme" parent="AppTheme">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@color/blue</item>
    </style>

</resources>

Upvotes: 1

siddhesh
siddhesh

Reputation: 563

All you need to do is set these properties in your theme:

true true

Your activity / container layout you wish to have a transparent status bar needs this property set:

android:fitsSystemWindows=”true”

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow(); // in Activity's onCreate() for instance
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

else go through this link would help you out

completely transparent status bar and navigation bar on lollipop

Hope it helps someone :).

Now I only need to make it backward compaitable.

Upvotes: 0

Related Questions