Reputation: 41
How do I remove the navigation bar to get Full Screen View?
So far I've tried setting the theme using:
<style name="AppTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
and
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
in styles.xml
and
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
in activity_main.xml
and i also tried
ActionBar ac = getSupportActionBar();
ac.hide();
even tried
requestWindowFeature(Window.FEATURE_NO_TITLE);
in my MainActivity.java but this only made action bar to disappear. I have
been trying for a few days now but can't figure this out.
Upvotes: 2
Views: 17850
Reputation: 2032
Try! call it in onCreate()
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
And
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
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_IMMERSIVE_STICKY);
}
}
UPDATE 07/08/2023 Fixed Deprecated
fun hideSystemUIOnCreate() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
@Suppress("DEPRECATION")
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
} else {
window?.let {
WindowCompat.setDecorFitsSystemWindows(it, false)
}
}
}
fun hideSystemUIOnWindowFocusChanged(view: View) {
//view is rootView (ex: binding.root)
val window = window ?: return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Tell the window that we want to handle/fit any system windows
WindowCompat.setDecorFitsSystemWindows(window, false)
val controller = view.windowInsetsController
// Hide the keyboard (IME)
controller?.hide(WindowInsets.Type.ime())
// Sticky Immersive is now ...
controller?.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// When we want to hide the system bars
controller?.hide(WindowInsets.Type.systemBars())
} else {
//noinspection
@Suppress("DEPRECATION")
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
}
Upvotes: 15
Reputation: 437
you need fullscreen layout try this:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN
);
add it in the onCreate of the Activity that you wanted to see fullscreen.
Upvotes: -1