Fullscreen Activity in Android?

后端 未结 30 2248
佛祖请我去吃肉
佛祖请我去吃肉 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 01:05

    If your using AppCompat and ActionBarActivity, then use this

    getSupportActionBar().hide();

    0 讨论(0)
  • 2020-11-22 01:07

    With kotlin this is the way I did:

    class LoginActivity : AppCompatActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_login)
            window.decorView.systemUiVisibility =
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                    View.SYSTEM_UI_FLAG_FULLSCREEN
    
        }
    }
    

    Immersive Mode

    The immersive mode is intended for apps in which the user will be heavily interacting with the screen. Examples are games, viewing images in a gallery, or reading paginated content, like a book or slides in a presentation. For this, just add this lines:

    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    

    Sticky immersive

    In the regular immersive mode, any time a user swipes from an edge, the system takes care of revealing the system bars—your app won't even be aware that the gesture occurred. So if the user might actually need to swipe from the edge of the screen as part of the primary app experience—such as when playing a game that requires lots of swiping or using a drawing app—you should instead enable the "sticky" immersive mode.

    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    

    For more information: Enable fullscreen mode

    In case your using the keyboard, sometimes happens that StatusBar shows when keyboard shows up. In that case I usually add this to my style xml

    styles.xml

    <style name="FullScreen" parent="AppTheme">
        <item name="android:windowFullscreen">true</item>
    </style>
    

    And also this line to my manifest

    <activity
            android:name=".ui.login.LoginActivity"
            android:label="@string/title_activity_login"
            android:theme="@style/FullScreen">
    
    0 讨论(0)
  • 2020-11-22 01:08

    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>
    </activity>  
    

    Or in Java code:

    protected void onCreate(Bundle savedInstanceState){
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    
    0 讨论(0)
  • 2020-11-22 01:08

    It worked for me.

    if (Build.VERSION.SDK_INT < 16) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    
    0 讨论(0)
  • 2020-11-22 01:09

    Using Android Studio (current version is 2.2.2 at moment) is very easy to add a fullscreen activity.

    See the steps:

    1. Right click on your java main package > Select “New” > Select “Activity” > Then, click on “Fullscreen Activity”.

    1. Customize the activity (“Activity Name”, “Layout Name” and so on) and click “finish”.

    Done!

    Now you have a fullscreen activity made easily (see the java class and the activity layout to know how the things works)!

    0 讨论(0)
  • 2020-11-22 01:09

    Inside styles.xml...

    <!-- No action bar -->
    <style name="NoActonBar" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Theme customization. -->
        <item name="colorPrimary">#000</item>
        <item name="colorPrimaryDark">#444</item>
        <item name="colorAccent">#999</item>
        <item name="android:windowFullscreen">true</item>
    </style>
    

    This worked for me. Hope it'll help you.

    0 讨论(0)
提交回复
热议问题