5

I want to change the status bar colour on pre-lollipop devices programmatically. I am well aware the material design colouPrimaryDark wont work on pre-lollipop as status bar colour is concern of OS itself which pre-lollipop devices wont provide such feature. So I want to do it programmatically through java file. Is that possible?

currently I am using this material design code.

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColor</item>
    <item name="colorAccent">@color/primaryColor</item>
</style>

As this wont work with API below 21. So I want to do it through java.

2 Answers2

1

Actually, we can use that on + KitKat.

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

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.

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • It's 24dp on Marshmallow. – Eugen Pechanec Feb 11 '16 at 21:54
  • 1
    It works on API 17. But we can not use the "scroll down to see notifications", as in general status bar. I also used activity.requestWindowFeature(Window.FEATURE_NO_TITLE); activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); – ashishdhiman2007 Jun 17 '17 at 09:51
0

Simply its not possible it the matter of the os itself to manage those things. pre-lollipop android versions won't gave such privilege to change status bar colour.