android設置背景色為透明


android設置背景色為透明

方法一:

僅僅要在配置文件內activity屬性配置內加上

android:theme="@android:style/Theme.Translucent" 

就好了。

這樣就調用了android的透明樣式。

方法二:

先在res/values下建colors.xml文件,寫入:
  
  <?

xmlversion="1.0"encoding="UTF-8"?

>
  
  <resources>
  
  <colorname="transparent">#9000</color>
  
  </resources>
  
  這個值設定了整個界面的透明度。為了看得見效果。如今設為透明度為56%(9/16)左右。
  
  再在res/values/下建styles.xml,設置程序的風格
  
  <?

xmlversion="1.0"encoding="utf-8"?

>
  
  <resources>
  
  <stylename="Transparent">
  
  <itemname="android:windowBackground">@color/transparent</item>
  
  <itemname="android:windowIsTranslucent">true</item>
  
  <itemname="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
  
  </style>
  
  </resources>
  
  最后一步,把這個styles.xml用在對應的Activity上。即在AndroidManifest.xml中的隨意<activity>標簽中加入
  
  android:theme="@style/transparent"
  
  假設想設置全部的activity都使用這個風格,能夠把這句標簽語句加入在<application>中。
  
  最后執行程序。哈哈。是不是發現整個界面都被蒙上一層半透明了。最后能夠把背景色#9000換成#0000,執行程序后,就全透明了,看得見背景下的全部東西能夠卻都操作無效。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM