Android 全透明效果

來源:互聯網
上載者:User

先在res/values下建colors.xml檔案,寫入:

  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2. < resources >   
  3.     < color   name = "transparent" > #9000 </ color >   
  4. </ resources >  

這個值設定了整個介面的透明度,為了看得見效果,現在設為透明度為56%(9/16)左右。

再在res/values/下建styles.xml,設定程式的風格

 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3.     <style name="Transparent">
  4.         <item name="android:windowBackground">@color/transparent</item>
  5.         <item name="android:windowIsTranslucent">true</item>   
  6.         <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
  7.     </style>
  8. </resources>

最後一步,把這個styles.xml用在相應的Activity上。即在AndroidManifest.xml中的任意<activity>標籤中添加

 

  1. android:theme = "@style/transparent"

如果想設定所有的activity都使用這個風格,可以把這句標籤語句添加在<application>中。

最後運行程式,哈哈,是不是發現整個介面都被蒙上一層半透明了。最後可以把背景色#9000換成#0000,運行程式後,就全透明了,看得見背景下的所有東西可以卻都操作無效。

來源

相關文章

聯繫我們

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