如何隱藏 Android 中的狀態列?
此示例演示如何在 Android 中進行操作。
步驟 1 − 在 Android Studio 中建立新專案,轉至檔案 ⇒ 新建專案並填寫所有必需資訊以建立新專案。
步驟 2 − 向 res/layout/activity_main.xml 新增以下程式碼。
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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" 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" /> </androidx.constraintlayout.widget.ConstraintLayout>
步驟 3 − 向 src/MainActivity.java 新增以下程式碼
import androidx.appcompat.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); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); } }
步驟 4 − 向 androidManifest.xml 新增以下程式碼
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="app.com.sample"> <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=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
讓我們嘗試執行應用程式。我假設你已經將實際 Android 移動裝置與電腦連線。要從 Android Studio 執行應用程式,請開啟專案的一個活動檔案,然後單擊工具欄中的“執行” 圖示。選擇你的移動裝置作為選項,然後檢視將預設螢幕顯示在移動裝置上的移動裝置 −
單擊 此處 下載專案程式碼。
廣告