Bottom Navigation Bar gets messed up after clearing flag translucent status flag - android

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window = getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS|
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//window.setStatusBarColor(getResources().getColor(R.color.profile_header));
window.setStatusBarColor(Color.parseColor("#f9fafc"));
}
check out screen shot here

Related

Android Window flag FLAG_TRANSLUCENT_STATUS is deprecated now, How to fix this?

I an trying to update status bar dynamically as below but getting warning that flag FLAG_TRANSLUCENT_STATUS is depricated now, how i can fix this?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// clear FLAG_TRANSLUCENT_STATUS flag:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// finally change the color
getWindow().setStatusBarColor(ContextCompat.getColor(this, color));
}
I spent too much hours to get the proper answer, because i have an error with status bar color as well. I will put the answer here if someone has the same problem.
You need to set the status bar color in transparent as you do in the code using the last build version as "if" statement, thats for sure.
But, also, you need to set this layout attribute in the root view as well.
android:fitsSystemWindows="false"
Hope this will help you resolving the status bar error in Android 30.
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else if (Build.VERSION.SDK_INT >= 19) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
//Virtual keyboard is also transparent
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}

change background color of notch through Code does not work

I tried changing the color of the status bar it work
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources().getColor(R.color.black));
}
but for the nocth diplay it does not work.
Try this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
}
Just remove: window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

FLAG_LAYOUT_NO_LIMITS for customizing status bar makes navigation bar overlapping

I searched for a solution to set a drawable for status bar and I found this :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
This code works fine but it makes another problem too!
If user's android device has bottom navigation buttons (software buttons) my layout goes behind it! of course this problem happens for top of my layouts too.
You can see it here
Is there a way to have a customized status bar while there is no problem with other items overlapping my layout?
This code solved my problem!
#Override
protected void onCreate(Bundle savedInstanceState) {
...
//make full transparent statusBar
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true);
}
if (Build.VERSION.SDK_INT >= 19) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
if (Build.VERSION.SDK_INT >= 21) {
setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false);
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
}
public static void setWindowFlag(Activity activity, final int bits, boolean on) {
Window win = activity.getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
}

Change status bar color in android api level 15

i used this library:
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
private void initStatusBar() {
Window window = getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setTintColor(ContextCompat.getColor(this, R.color.colorBlack));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
window.setStatusBarColor(Color.TRANSPARENT);
}
}
This method is called in main activity before setContentView(). It's working but the status bar content items are all white, so nothing seen, I want black color status bar content text.
My min sdk version is 15 and max 26. My background is a png file. so I want the same in status bar.

Android status bar color not changing

I have an Activity and a Fragment in my project.In the Activity I set the layout take the entire screen and in fragment I try to change the status bar color programmatically. The status bar is shown over the layout but the color is not changed.
Activity:
if (Build.VERSION.SDK_INT > 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Fragment:
if (Build.VERSION.SDK_INT > 16) {
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
if (Build.VERSION.SDK_INT >= 21) {
Log.e("statusbarcolor","changing..");
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getContext(),R.color.statusBarColor));
}
}
I guess , Problem is your Build.VERSION.SDK_INT section .
In my case (Activity)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor("#54d66a");
}
I did it finally.I simply used the below code in my fragment:
getActivity().getWindow().clearFlags(WindowManager.FLAG_FULL_SCREEN);
User this code
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.my_statusbar_color));
}
Just try doing:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.BLUE);
}
Just tested this with ActionBarActivity and it works alright.
Note: Setting the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag programmatically is not necessary if your values-v21 styles file has it set already, via:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
Create a method in your activity
public void updateStatusBarColor(String color){// Color must be in hexadecimal fromat
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor(color));
}
}
Call this method from your fragment
((ActivityName)getActivity()).updateStatusBarColor("#000000")
In given below using my application :
..................
switch (position) {
case 0 :
fragment = new SampleOneFragment();
color = R.color.ColorPrimaryDark;
break;
case 1:
fragment = new SampleOneFragment();
color = R.color.AlertRed_dark;
break;
case 2:
fragment = new SampleOneFragment();
color = R.color.ProgressBarPurple_dark;
break;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(ContextCompat.getColor(this, color));
}
replaceFragment(fragment);
}

Categories

Resources