I have created a function as below which sets fitSystemWindow attribute :
private void setFitSystemWindows() {
try {
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP) {
// Do something for lollipop and above versions
View view = findViewById(R.id.relRoot);
view.setFitsSystemWindows(true);
view.setPadding(0, 0, 0, 0);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(ContextCompat.getColor(CameraActivity.this, R.color.colorBlackTransperent));
} else {
// do something for phones running an SDK before lollipop
View view = findViewById(R.id.relRoot);
view.setFitsSystemWindows(false);
view.setPadding(0, 0, 0, 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Let me explain it :
Here, R.id.relRoot
is the parent root RelativeLayout
in layout xml file.
I am checking build version first and If build version is greater than Lollipop, am setting fitsSystemWindows
to true
and if not then setting it to false
.
But, still when I run the application in devices > Lollipop, am getting my status bar color white and bottom soft view (which contains back,home and recent) also with the color white.
You can see I am also using method setStatusBarColor
but it's not working.
What might be the issue ?
NOTE : Am checking in emulator device : NEXUS 5X API 27 (Android 8.1.0, API 27)