Search code examples
androidandroid-5.0-lollipopandroid-statusbar

Status Bar Color - Android Studio


How do I change the Status Bar Color of my app that I'm making in Android Studio so that it changes to a static color on Android Lollipop 5.0 or higher and doesn't crash on Mobile running lower version of Android OS.


Solution

  • Try using this, this works for me

    //changing statusbar
    if (android.os.Build.VERSION.SDK_INT >= 21){
                    Window window = this.getWindow();
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    window.setStatusBarColor(this.getResources().getColor(R.color.primary_dark));
                }
    

    For changing color ActionBar :

     <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
            <item name="android:background">#ffff00</item>
        </style>
    

    and declare on your manifest in application tag

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/MyActionBar" >
    

    hope it help