1

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"
toha
  • 5,095
  • 4
  • 40
  • 52
ZeeRooo
  • 31
  • 5

4 Answers4

1

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>
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
1
<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.

dipali
  • 10,966
  • 5
  • 25
  • 51
  • No, because when im in the navigation menu, the status bar is fully blue and should be transparent: https://i.stack.imgur.com/dBhcd.png – ZeeRooo Oct 22 '16 at 04:59
1

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);
Waqas Ahmed Ansari
  • 1,683
  • 15
  • 30
  • If i use `Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(YOUR_COLOR);` on settings activity _(color.transparent)_ it use the white background and no the color of toolbar. My app have theme engine (different colors to choose) and i need the status bar with the same color as the theme. – ZeeRooo Dec 04 '16 at 17:14
0

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.

Community
  • 1
  • 1
siddhesh
  • 563
  • 1
  • 9
  • 15