Android視窗背景的最佳化

來源:互聯網
上載者:User

標籤:android   style   http   io   ar   java   sp   檔案   on   

視圖有背景,每個視窗也是有背景的。每一Activity是一個視窗,每一個Activity都有不同得背景。介面的繪畫順序如下:視窗——跟視圖 ——子視圖。當我們的跟視圖已經覆蓋了整個視窗的時候 ,程式還是會畫一個透明的視窗的背景,而這個背景使用者是看不到的。我們就需要想辦法讓程式在這樣的情況下去掉視窗背景,節約畫視窗背景的時間提高效率。


刪除視窗背景的方法:


一、java代碼中


public void onCreate(Bundle icicle){ 
 super.onCreate(icicle);
 setContentView(R.layout.mainview);
 // 刪除視窗背景
 getWindow().setBackgroundDrawable(null);
 ...

二、在xml檔案中


首先在res/values/style.xml 檔案中定義如下:
<resources>
<style name="NoBackgroundTheme" parent="android:Theme">
 <item name="android:windowBackground">@null</item>
</style>
</resources>


然後在AndroidManifest.xml檔案中 找到要去掉背景的activity   書寫代碼如下: 
<activity android:name="MyApplication" android:theme="@style/NoBackgroundTheme"> ... </activity>

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.