I am trying to hide status bar in Android 10. I've already read a lot of answers to similar questions, but they don't work for my device. The goal is to use the space of the status bar as a part of application view:
Some of the solutions described below work on emulator, but don't work on my physical device (Redmi Note 10, API version 29).
I would appreciate any advice.
What I have tried:
- Using different predefined styles like
@android:style/Theme.NoTitleBar.Fullscreen
and so on. - Using different style attributes including:
android:windowFullscreen
,fitsSystemWindows
etc. - Setting different styles in program code using setSystemUiVisibility including
SYSTEM_UI_FLAG_FULLSCREEN
,SYSTEM_UI_FLAG_IMMERSIVE_STICKY
,SYSTEM_UI_FLAG_HIDE_NAVIGATION
,SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
,SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
,SYSTEM_UI_FLAG_LAYOUT_STABLE
. - Adding and removing different flags using clearFlags, addFlags and setFlags.
- Setting status bar color to transparent using setStatusBarColor.
- Requesting different features using requestWindowFeature.
- Changing layout top padding to negative values.
- Using insets by defining applyTopWindowInsetsForView and onApplyWindowInsets functions.
What I've managed to do.
I've managed to get two results, but neither of them is good for me.
- Translucent status bar.
- Completely black status bar without taking its space for app view.
UPDATE 10 May 2022:
According to the following answer it is impossible to use WindowInsetsController
on API 29 or earlier: How do I hide the status bar in my Android 11 app?
SOLUTION 1
Proposed by @Zain.
Activity:
protected void onCreate(Bundle savedInstanceState) {
...
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
WindowInsetsControllerCompat windowInsetsCompat = new WindowInsetsControllerCompat(getWindow(), getWindow().getDecorView());
windowInsetsCompat.hide(WindowInsetsCompat.Type.statusBars());
windowInsetsCompat.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
...
theme.xml:
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
SOLUTION 2
Activity:
protected void onCreate(Bundle savedInstanceState) {
...
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LOW_PROFILE
);
...
theme.xml:
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>