android設定Activity背景色為透明的2種方法

來源:互聯網
上載者:User

標籤:

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>   <style name="Transparent">    <item name="android:windowBackground">@color/transparent</item>    <item name="android:windowIsTranslucent">true</item>    <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>    </style>    </resources>

 

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

android:theme="@style/transparent"

 


  
  如果想設定所有的activity都使用這個風格,可以把這句標籤語句添加在<application>中。
  
  最後運行程式,是不是發現整個介面都被蒙上一層半透明了。最後可以把背景色#9000換成#0000,運行程式後,就全透明了,看得見背景下的所有東西可以卻都操作無效。

android設定Activity背景色為透明的2種方法

聯繫我們

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