I'd like to set windowTranslucentStatus to true when the user is on lollipop and above because otherwise (at least on kitkat) the app bar appears inside the system bar. On lollipop it is fine. Without making separate styles.xml for each version which apparently you shouldn't have to do anymore how can I set it in java?
I have the following code in my mainActivity but don't know hot windowTranslucentStatus... Any ideas?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// set windowTranslucentStatus = true
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = getWindow(); // in Activity's onCreate() for instance
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
You can switch between translucent or not whenever you want using this :
public static void setTranslucent(Activity activity, boolean translucent){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = activity.getWindow();
if(translucent) {
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
else{
w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With