如何永久停用 Android 中的操作欄?


此示例演示如何在 Android 中永久停用操作欄。

步驟 1 − 在 Android Studio 中建立新專案,轉到檔案 ⇒ 新專案並填寫所有必需的詳細資訊以建立一個新專案。

步驟 2 − 將以下程式碼新增到 res/layout/activity_main.java

<? xml version= "1.0" encoding= "utf-8" ?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
   xmlns: tools = "http://schemas.android.com/tools"
   android :layout_width= "match_parent"
   android :layout_height= "match_parent"
   android :orientation= "vertical"
   tools :context= ".MainActivity" >
   <TextView
      android :layout_width= "match_parent"
      android :layout_height= "wrap_content"
      android :layout_centerInParent= "true"
      android :gravity= "center"
      android :text= "No Action Bar"
      android :textAppearance= "@style/Base.TextAppearance.AppCompat.Large" />
</RelativeLayout>

步驟 3 − 將以下程式碼新增到 src/MainActivity.java

package app.tutorialspoint.com.sample ;
import android.os.Bundle ;
import android.support.v7.app.AppCompatActivity ;
public class MainActivity extends AppCompatActivity {
   @Override
   protected void onCreate (Bundle savedInstanceState) {
      super .onCreate(savedInstanceState) ;
      setContentView(R.layout. activity_main ) ;
   }
}

步驟 4 − 將以下程式碼新增到 res/values/styles.xml

<resources>
   <!-- Base application theme. -->
   <style name= "AppTheme" parent= "Theme.AppCompat.Light.DarkActionBar" >
      <!-- Customize your theme here. -->
      <item name= "colorPrimary" > @color/colorPrimary </item>
      <item name= "colorPrimaryDark" > @color/colorPrimaryDark </item>
      <item name= "colorAccent" > @color/colorAccent </item>
   </style>
   <style name= "AppTheme.NoActionBar" >
      <item name= "windowActionBar" > false </item>
      <item name= "windowNoTitle" > true </item>
   </style>
</resources>

步驟 5 − 將以下程式碼新增到 androidManifest.xml

<? xml version= "1.0" encoding= "utf-8" ?>
<manifest xmlns: android = "http://schemas.android.com/apk/res/android"
   package= "app.tutorialspoint.com.sample" >
   <uses-permission android :name= "android.permission.VIBRATE" />
   <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 執行應用程式,請開啟一個專案活動檔案並點選工具欄中的執行 圖示。選擇你的移動裝置作為選項,然後檢查你的移動裝置,它將會顯示你的預設螢幕 –

更新時間: 30-Jul-2019

447 瀏覽量

職業生涯起航

完成課程以獲得認證

開始
廣告
© . All rights reserved.