How to hide status bar in android in just one activity
If you want to remove status bar then use this before setContentView(layout) in onCreateView method
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
credits
How do I hide the status bar in my Android 11 app?
When your device is API-30 (Android 11; minSdkVersion 30) or later , setSystemUiVisibility
is deprecated and you can use the newly introduced WindowInsetsController
instead. (And note that you cannot use WindowInsetsController
on API-29 or earlier).
So the official reference says:
This method was deprecated in API level 30.
SystemUiVisibility flags are deprecated. UseWindowInsetsController
instead.
You should use WindowInsetsController
class.
in Kotlin:
window.decorView.windowInsetsController!!.hide(
android.view.WindowInsets.Type.statusBars()
)
in Java:
getWindow().getDecorView().getWindowInsetsController().hide(
android.view.WindowInsets.Type.statusBars()
);
If you also want to hide NavigationBar:
in Kotlin:
window.decorView.windowInsetsController!!.hide(
android.view.WindowInsets.Type.statusBars()
or android.view.WindowInsets.Type.navigationBars()
)
in Java:
getWindow().getDecorView().getWindowInsetsController().hide(
android.view.WindowInsets.Type.statusBars()
| android.view.WindowInsets.Type.navigationBars()
);
Hide status bar in Android 10 (API 29) and use its space in the application
You need to display contents content edge-to-edge in your app (Documentation reference)
Step 1: Use: WindowCompat.setDecorFitsSystemWindows(window, false)
This is the primary step for ensuring that your app goes edge-to-edge, that is, laid out using the entire width and height of the display. Use WindowCompat.setDecorFitsSystemWindows(window, false) to lay out your app behind the system bars, as shown in the following code example:
Step 2: Hide the status bar using WindowInsetsControllerCompat
:
WindowInsetsControllerCompat(window, window.decorView).apply {
// Hide the status bar
hide(WindowInsetsCompat.Type.statusBars())
// Allow showing the status bar with swiping from top to bottom
systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
Step 3: As from step 1 the activity contents at the bottom will be obscured by the bottom navigation bar; then you need to adjust the bottom margin of the root layout of the activity to height of the navigation bar by using WindowInsetsListener
:
Kotlin:
// root layout of your activity
val root = findViewById<ConstraintLayout>(R.id.root)
ViewCompat.setOnApplyWindowInsetsListener(
root
) { view: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.layoutParams = (view.layoutParams as FrameLayout.LayoutParams).apply {
// draw on top of the bottom navigation bar
bottomMargin = insets.bottom
}
// Return CONSUMED if you don't want the window insets to keep being
// passed down to descendant views.
WindowInsetsCompat.CONSUMED
}
Java:
WindowInsetsControllerCompat windowInsetsCompat = new WindowInsetsControllerCompat(getWindow(), getWindow().getDecorView());
windowInsetsCompat.hide(WindowInsetsCompat.Type.statusBars());
windowInsetsCompat.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
// root layout of your activity
ConstraintLayout root = findViewById(R.id.root);
ViewCompat.setOnApplyWindowInsetsListener(
root
, (view, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.bottomMargin = insets.bottom;
return WindowInsetsCompat.CONSUMED;
});
Step 4: Finally make sure that drawing in cutout area is allowed in your app's theme:
<item name="android:windowLayoutInDisplayCutoutMode">always</item>
Android - hide status and navigation bar completely for an app with nav drawer and app bar
Update
The issue was with your layout file. I just set android:fitsSystemWindows=false
to fix the issue. I made a pull request to your repo, which I think solves your issue.
You should follow the following official documentations:
- Hide the status bar
- Hide the navigation bar
Hide the Status Bar on Android 4.0 and Lower
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
...
}
Hide the Status Bar on Android 4.1 and Higher
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
Hide the Navigation Bar
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Related Topics
Get Spinner Selected Items Text
How To: Define Theme (Style) Item for Custom Widget
Noclassdeffounderror with Android Studio on Android 4
Android Emulator: Could Not Get Wglgetextensionsstringarb Error
How to Use Asynctask to Show a Progressdialog While Doing Background Work in Android
Share Sqlite Database Between 2 Android Apps
Android: How to Detect Double-Tap
Is Uploading Videos from an Sd Card to Facebook Possible with the Facebook Sdk
Help with Passing Arraylist and Parcelable Activity
Android Overriding Onbackpressed()
How to Prevent Android Bluetooth Rfcomm Connection from Dying Immediately After .Connect()
Quality Problems When Resizing an Image at Runtime
How to Cancel This Repeating Alarm
Add Extra User Information with Firebase
Sharing Data Between Fragments Using New Architecture Component Viewmodel
Resolved Versions for App (22.0.0) and Test App (21.0.3) Differ