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.
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 withSystemTintBar
: 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
.