Android 去掉狀態列的方法匯總_Android

來源:互聯網
上載者:User

在實際的應用程式開發中,我們有時需要把 Activity 設定成全螢幕顯示,一般情況下,可以通過兩種方式來設定全螢幕顯示效果:

其一,通過在代碼中可以設定,

其二,通過manifest設定檔來設定全屏。

其一:在代碼onCreate裡面setContentView之前設定(如下)

view plaincopy to clipboardprint?public 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.main); }

但要注意的是:在代碼中設定的話,設定無標題和設定全屏的兩段代碼要放置在 setContentView(R.layout.main)(介面渲染,完成了再全屏是不行的)這段代碼的前面。要不然會報錯。

其二:在manifest設定檔中設定

第一種方法

①在res/values 目錄建立個theme.xml檔案(用來放樣式)

<?xml version="1.0" encoding="utf-8"?> <resources> <!-- name 是Style的名稱,parent 繼承那個父類樣式 --> <style name="theme_fullScreen" parent="android:Theme.Black"> <item name="android:windowNoTitle">true</item> <!-- 設定無標題 --> <item name="android:windowFullscreen">?android:windowNoTitle</item> <!-- 是否填充慢螢幕,引用android:windowNoTitle 的值 ?android:windowNoTitle,取決於android:windowNoTitle的值--></style> </resources>

②<activity android:name=".login.LoginActivity" android:theme="@style/theme_fullScreen"/>

第二種方法

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.andyidea" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".login.LoginActivity" android:theme="@android :style/Theme.NoTitleBar.Fullscreen" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

只去程式標題列 設定整個應用 no title

第三種:這種在一般的應用中不常用,就是在res/values目錄下面建立一個style.xml的檔案例如:

<?xml version="1.0" encoding="UTF-8" ?> <resources> <style name="theme_notitle"> <item name="android:windowNoTitle">true</item> </style> </resources>

這樣,我們就自訂了一個style,就相當於一個主題,然後在AndroidManifest.xml檔案中定義

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/theme_notitle">

這樣也可以達到去掉標題列的效果

以上給大家總結了三種android去掉狀態列的方法,希望本文所述能夠協助到大家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.