Set windowTranslucentStatus = true when android lollipop or higher

I would like to set windowTranslucentStatus to true when the user is on a lollipop and above, because otherwise (at least on kitkat) the application panel appears inside the system panel. On a lollipop this is normal. Without creating separate styles.xml for each version, which apparently you no longer have to do, how can I install it in java?

I have the following code in my mainActivity, but don’t know the TranslucentStatus hot window ... Any ideas?

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // set windowTranslucentStatus = true } 
+6
source share
2 answers
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window w = getWindow(); // in Activity 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); } 
+20
source

You can switch between translucent or not when you want to use 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); } } 
0
source

Source: https://habr.com/ru/post/984011/


All Articles