Android Studio设置全屏Activity

方法一:在创建项目的时候选择全屏Activity

Android Studio设置全屏Activity_第1张图片

运行结果

Android Studio设置全屏Activity_第2张图片

方法二:创建空白项目

Android Studio设置全屏Activity_第3张图片

修改代码

第一步:添加如下代码
Android Studio设置全屏Activity_第4张图片
第二步:添加如下代码
Android Studio设置全屏Activity_第5张图片
第三步:放置一张背景图片
Android Studio设置全屏Activity_第6张图片
第四步添加如下代码
Android Studio设置全屏Activity_第7张图片

修改具体代码(我直接给代码)

MainActivity .java

package com.example.a10212.fullscreen;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.a10212.fullscreen">

    <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">
        <activity android:name="com.example.a10212.fullscreen.MainActivity"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            intent-filter>
        activity>
    application>

manifest>

activity_main.xml


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/timg"
    tools:context=".MainActivity">



android.support.constraint.ConstraintLayout>

运行结果

Android Studio设置全屏Activity_第8张图片

方法三

情况一

当下面方法继承的时候

public class MainActivity extends AppCompatActivity

采用如下策略

package com.example.a10212.fullscreen;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //去掉顶部标题
        getSupportActionBar().hide();
        //去掉最上面时间、电量等
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);


    }
}

activity_main.xml(设置Activity背景)


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/timg"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

android.support.constraint.ConstraintLayout>

运行结果

Android Studio设置全屏Activity_第9张图片

情况二

当下面方法继承的时候

public class MainActivity extends Activity

采用如下策略(this.requestWindowFeature(Window.FEATURE_NO_TITLE);写在 setContentView(R.layout.activity_main);之前)

package com.example.a10212.fullscreen;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         //去掉顶部标题
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        //去掉最上面时间、电量等
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);


    }
}

运行结果

Android Studio设置全屏Activity_第10张图片

你可能感兴趣的:(Android Studio设置全屏Activity)