去掉android的螢幕上的title bar

來源:互聯網
上載者:User

在進行android開發時,每個Activity會預設帶上一個title bar用以顯示程式名,有時為了擴大螢幕的顯示地區需要去掉這個title bar,去掉螢幕上的title bar有3個方法,

第一個方法是在代碼去掉title bar

在Activity的onCreate中加入如下代碼:

Java代碼
  1. this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

 但是使用這種方法,是在Activity將要顯示的時候,仍然會出現title bar,然後再將其去掉,使用者體驗不好。

第二種方法是使用style設定檔,步驟如下:

1.在res/values檔案夾下建立一個xml檔案,名為mainStyle.xml,內容如下:

Java代碼
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <resources>   
  3.     <style name="NoTitle" parent="android:Theme">   
  4.         <item name="android:windowNoTitle">true</item>   
  5.     </style>   
  6. </resources>  
<?xml version="1.0" encoding="utf-8"?><resources>    <style name="NoTitle" parent="android:Theme">        <item name="android:windowNoTitle">true</item>    </style></resources>

 

2.然後在AndroidManifest.xml中需要去掉title bar的activities的節點上加上一個樣式屬性,代碼如下:

Java代碼
  1. <activity android:name=".view.AutoTaskDemo" android:label="@string/app_name"  
  2.             android:configChanges="keyboardHidden|orientation|locale" android:theme="@style/NoTitle">  
<activity android:name=".view.AutoTaskDemo" android:label="@string/app_name"android:configChanges="keyboardHidden|orientation|locale" android:theme="@style/NoTitle">

 第三種方法是直接在AndroidManifest.xml中進行修改,

把需要去掉title bar的activities的節點上加上一個樣式屬性,代碼如下:

Java代碼
  1. <activity android:name=".view.SettingActivity"  
  2.             android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.NoTitleBar"/>  
<activity android:name=".view.SettingActivity"android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.NoTitleBar"/>

 

也可以在AndroidManifest.xml檔案的application節點上修改,對所有的activity都有效,代碼如下:

Java代碼
  1. <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">  
相關文章

聯繫我們

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