Android 去掉title bar的3個方法

來源:互聯網
上載者:User

標籤:

1. Java代碼實現

@Overridepublic void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);         setContentView(R.layout.main);        //...}

留意這語句所在的位置的,似乎所有requestWindowFeature的操作都要放在setContentView的前面。
但使用這種方法,使用者體驗不太好,在Activity將要顯示時,仍然會出現title bar,然後再去掉的。

2. 自訂style設定檔
在\res\values裡面的style.xml添加:

<?xml version="1.0" encoding="utf-8"?><resources>        <style name="NoTitle" parent="android:Theme">                <item name="android:windowNoTitle">true</item>        </style></resources>

這裡的代碼應該看明白了吧!
然後在AndroidManifest.xml檔案裡,給需要去掉title bar的activity的節點上加上android:theme="@style/NoTitle,代碼如下:

<activity android:name=".MainActivity"                    android:configChanges="orientation|keyboardHidden"                    android:theme="@style/NoTitle" />

3. 直接在AndroidManifest.xml中進行修改
原來我們可以無需自訂style配置的,直接調用系統的就行了:

<activity android:name=".MainActivity"                    android:configChanges="orientation|keyboardHidden"                    android:theme="@android:style/Theme.NoTitleBar" />

如果我們要設定整個Application都去掉title bar,那麼就設定application:

<application android:icon="@drawable/lightbulb" android:label="@string/app_name"                    android:theme="@android:style/Theme.NoTitleBar">

 

Android 去掉title bar的3個方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.