android activity 如何設置透明

在manifest 文件中 設置 activity 的屬性如下:


 <activity android:name=".ShortcutdemoActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.Translucent"
                  >


第三行是控制透明的屬性。


另轉:

http://norety.iteye.com/blog/648725

 

res/values/styles.xml

Xml代碼  收藏代碼
  1. <resources>  
  2.   <style name="Transparent  
  3. ">  
  4.     <item name="android:windowBackground">@color/transparent_background</item>  
  5.     <item name="android:windowNoTitle">true</item>  
  6.     <item name="android:windowIsTranslucent">true</item>    
  7.     <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>  
  8.   </style>  
  9. </resources>  

 res/values/color.xml

Xml代碼  收藏代碼
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.   <color name="transparent_background">#50000000</color>  
  4. </resources>  

注意:color.xml的#5000000前兩位是透明的效果參數從00--99(透明--不怎麼透明),後6位是顏色的設置 

 

manifest.xml

Xml代碼  收藏代碼
  1. <activity android:name=".TransparentActivity" android:theme="@style/Transparent">  
  2. </activity>  

 

 

java代碼

Java代碼  收藏代碼
  1. public void onCreate(Bundle savedInstanceState) {  
  2.         super.onCreate(savedInstanceState);  
  3.         setTheme(R.style.Transparent);   
  4.         setContentView(R.layout.transparent);  
  5. }  

 配置結束!



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章