Android Material: Status Bar Color Won't Change

Android Material: Status bar color won't change

The status bar is a system window owned by the operating system. On pre-5.0 Android devices, applications do not have permission to alter its color, so this is not something that the AppCompat library can support for older platform versions. The best AppCompat can do is provide support for coloring the ActionBar and other common UI widgets within the application.

Can't change color of status bar

I think that i have found the most elegant solution based on the other answers:

The only thing i changed was added the flag in the OnCreate(Bundle bundle) function:

 protected override void OnCreate(Bundle bundle)
{
if ((int)Build.VERSION.SdkInt >= (int)BuildVersionCodes.Lollipop)
Window.AddFlags(Android.Views.WindowManagerFlags.DrawsSystemBarBackgrounds);

base.OnCreate(bundle);

// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}

And that's it! The style files do the rest, and on older version of android, the status bar just won't change.

Using the Material Theme colorPrimary status bar won't change

need import:

compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'    

and next add this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow(); // in Activity's onCreate() for instance
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
// enable status bar tint
tintManager.setStatusBarTintEnabled(true);
// enable navigation bar tint
tintManager.setNavigationBarTintEnabled(true);

// set a custom tint color for all system bars
tintManager.setTintColor(Color.BLUE);

Android - Change status bar color on pre-lollipop devices programatically

Actually, we can use that on + KitKat.

Check this link: http://developer.android.com/reference/android/R.attr.html#windowTranslucentStatus

  • Has been added in API level 19 which means, there is a way to do that.check my blog about using it with SystemTintBar:
    https://linx64.ir/blog/2016/02/05/translucent-statusbar-on-kitkat/
  • And this is the another method(without using CoordinatorLayout): Translucent StatusBar on kitkat with FrameLayout above the Toolbar and using CoordinatorLayout

Just add this to the top of your layout:

<FrameLayout
android:id="@+id/statusbar"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="@color/colorPrimaryDark" />

And use this:

if(Build.VERSION.SDK_INT == 19) {

FrameLayout statusbar = (FrameLayout) findViewById(R.id.statusbar);
statusbar.setVisibility(View.GONE);
}

It should work on Kitkat, and like i said, this is also available only for + Kitkat.

How to change the colour of the statusbar in android?

As stated above, set the colorPrimaryDark attribute in your style to whatever you like.

<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
</style>
</resources>

http://developer.android.com/training/material/theme.html

To do it correctly you should declare your color value in the color.xml, then reference it from the style.

Change status bar text color when primaryDark is white

I'm not sure what API level your trying to target, but if you can use API 23 specific stuff, you can add the following to your AppTheme styles.xml:

<item name="android:statusBarColor">@color/colorPrimaryDark</item>
<item name="android:windowLightStatusBar">true</item>

when android:windowLightStatusBar is set to true, status bar text color will be able to be seen when the status bar color is white, and vice-versa
when android:windowLightStatusBar is set to false, status bar text color will be designed to be seen when the status bar color is dark.

Example:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Status bar stuff. -->
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
<item name="android:windowLightStatusBar">true</item>
</style>


Related Topics



Leave a reply



Submit