How do I make an activity full screen? I mean without the notification bar. Any ideas?
There's a technique called Immersive Full-Screen Mode available in KitKat.
Example
Try this with appcompat from style.xml
. It provides support for all platforms.
<!-- Application theme. -->
<style name="AppTheme.FullScreen" parent="AppTheme">
<item name="android:windowFullscreen">true</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />
On Android 10, none worked for me.
But I that worked perfectly fine (1st line in oncreate):
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE;
decorView.setSystemUiVisibility(uiOptions);
setContentView(....);
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
enjoy :)
If you don't want to use the theme @android:style/Theme.NoTitleBar.Fullscreen
because you are already using a theme of you own, you can use android:windowFullscreen
.
In AndroidManifest.xml:
<activity
android:name=".ui.activity.MyActivity"
android:theme="@style/MyTheme">
</activity>
In styles.xml:
<style name="MyTheme" parent="your parent theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
Be careful with
requestWindowFeature(Window.FEATURE_NO_TITLE);
If you are using any method to set the action bar as the follow:
getSupportActionBar().setHomeButtonEnabled(true);
It will cause a null pointer exception.
https://developer.android.com/training/system-ui/immersive.html
Activity :
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
decorView.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);
}
}
AndroidManifests:
<activity android:name=".LoginActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_login"
android:theme="@style/FullscreenTheme"
></activity>