To change status bar background color, setup the following in your v21/style.xml, inside your style.
Yes, they are only working after API 21.
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@color/bgStatusBar</item>
For API level > 19
In older version, API level 19, cannot change background color on status bar.
But you can setup a ImageView behide it, and make the status bar full transprant.
Write down the following in your v19/style.xml, inside your style.
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">false</item>
In your Activity, add those code at onCreate()
// Lower then API level 19, do nothing
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
// Change the background image / color of the st
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
if (contentView.getChildCount() > 1) {
contentView.removeViewAt(1);
}
int res = resources.getIdentifier("status_bar_height", "dimen", "android");
int height = 0;
if (res != 0)
height = resources.getDimensionPixelSize(res);
ImageView image = new ImageView(activity);
image.setLayoutParams(
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height)
);
image.setImageResource(imageRes);
image.setScaleType(ImageView.ScaleType.FIT_XY);
contentView.addView(image);
}
Moreover, it is suggested to keep the fitsSystemWindows at style or the root layout.
To use adjustResize function to solve keyboard overlap edittext problem, it must be kept.
<item name="android:fitsSystemWindows">true</item>
You must be logged in to post a comment.