5

How can I check if translucent navigation is available ?

I am currently setting it to translucent with:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 

    translucentNavigation = true; 
    Window w = getWindow();  
    w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 

} 

But since I saw that it gets disabled for some devices (like the N10) and of course it is disabled if hardkeys are present, I'd like to check after setting the FLAG if it is translucent or before if it available at all.

stefple
  • 1,007
  • 17
  • 28
  • I am trying to set translucentNavigation in onCreate(). When I add the above code, Android Studio says - Cannot resolve symbol. Can you please tell me what I am missing? – user2731584 Jan 13 '15 at 15:51
  • I solved the issue by using the following code. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ Window w = getWindow(); w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } – user2731584 Jan 13 '15 at 16:25

1 Answers1

21

On KitKat devices, translucent system bars can be disabled with a framework boolean configuration resource. You can inspect the value of that resource at runtime.

int id = getResources().getIdentifier("config_enableTranslucentDecor", "bool", "android");
if (id == 0) {
    // not on KitKat
} else {
    boolean enabled = getResources().getBoolean(id);
    // enabled = are translucent bars supported on this device
}
pepyakin
  • 2,217
  • 19
  • 31
jspurlock
  • 1,466
  • 10
  • 7