Fullscreen Activity in Android?

后端 未结 30 2247
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 00:12

How do I make an activity full screen? I mean without the notification bar. Any ideas?

相关标签:
30条回答
  • 2020-11-22 00:42

    There's a technique called Immersive Full-Screen Mode available in KitKat. Immersive Full-Screen Mode Demo

    Example

    0 讨论(0)
  • 2020-11-22 00:42

    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" />
    
    0 讨论(0)
  • 2020-11-22 00:42

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

    0 讨论(0)
  • 2020-11-22 00:44

    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>
    
    0 讨论(0)
  • 2020-11-22 00:45

    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.

    0 讨论(0)
  • 2020-11-22 00:45

    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>
    
    0 讨论(0)
提交回复
热议问题