检查半透明导航是否可用

ste*_*ple 5 android

如何检查半透明导航是否可用?

我目前将其设置为半透明:

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); 

} 
Run Code Online (Sandbox Code Playgroud)

但是因为我看到它被禁用了某些设备(比如N10),当然如果存在硬键就会被禁用,我想在设置FLAG之后检查它是否是半透明的,或者之前是否可用.

小智 21

在KitKat设备上,可以使用框架布尔配置资源禁用半透明系统栏.您可以在运行时检查该资源的值.

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
}
Run Code Online (Sandbox Code Playgroud)