Using full screen Activity

梦想的初衷 提交于 2019-11-30 18:27:28

Try this to set activity to fullscreen:

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);

You can put this code in onCreate() method

You can try following code.

style.xml:

<style name="AppTheme.NoTitle" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

AndroidManifest.xml:

<activity
    android:name=".FullScreenActivity"
    android:theme="@style/AppTheme.NoTitle"
    android:screenOrientation="portrait"
    android:launchMode="singleTop">
</activity>

None of the answers above works correctly; they have problems with the onResume() method, and end up showing the soft keys.

The correct way to do it is pretty straightforward. Override this method in the Activity that should be fullscreen:

@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);
    }
}

That's if you want "Sticky Immersion". Check out the full doc here, and decide what is better for your use case.

What you wanted is called Imersive mode, which works on Android 4.4 and Above

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);

Official Documentation can be found here

In AndroidManifest.xml file

<activity
       android:name=".Launch"
       android:label="@string/app_name"
       android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <!-- This line is important -->

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

and your class should extends Activity not AppCompatActivity...

You can simply go to your manifest file and add android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to your <activity /> or <application /> tag in your Manifest file depending upon your requirement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!