Two ways to set full screen display in Android studio

Two ways to set full screen in Androidstudio, the second is recommended

The first type (set in the Java file)

Set directly in the onCreate() function

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
package com.example.app; //包名,自己设置一下
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
public class MainActivity extends Activity {
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //设置全屏显示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}

The second type (set in the xml file)

The first step (set in styles.xml)

insert image description here

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme.FullScreen" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>
</resources>

The second step (set in AndroidManifest.xml)


Select the theme android:theme="@style/AppTheme.FullScreen" in this file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.animee.localmusic">
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.FullScreen">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

at last

Another way is to choose the theme style that comes with Android,
like this (Theme.MaterialComponents.DayNight.NoActionBar.Bridge),
you can search for it yourself.

Guess you like

Origin blog.csdn.net/weixin_51033461/article/details/128505088
Recommended