Android 设置dialog背景全透明无边框的最简单的方法

做dialog的全透明无边框背景,网上找了n久,都有问题,其实很简单,就两句搞定。

<style name="Translucent_NoTitle" parent="android:style/Theme.Dialog">

<item name="android:background">#00000000</item> <!-- 设置自定义布局的背景透明 -->
<item name="android:windowBackground">@android:color/transparent</item>  <!-- 设置window背景透明,也就是去边框 -->
</style>

 

其他的都可以不用设置,有些属性会继承下来,唯一一个没被继承的是 <item name="android:windowIsTranslucent">true</item>,这个不设置也没影响
 
此方法同样可以用于activity,设置activity半透明
res/values/styles.xml

<resources>  
  <style name="Transparent  ">  
    <item name="android:windowBackground">@color/transparent_background</item>  
    <item name="android:windowNoTitle">true</item>  
    <item name="android:windowIsTranslucent">true</item>    
    <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>  
  </style>  
</resources>  
 res/values/color.xml

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
  <color name="transparent_background">#50000000</color>  
</resources>  

注意:color.xml的#5000000前两位是透明的效果参数从00--99(透明--不怎么透明),后6位是颜色的设置 

manifest.xml

<activity android:name=".TransparentActivity" android:theme="@style/Transparent">  
</activity>  

 

posted @ 2012-10-31 16:17  muzhi121  阅读(37977)  评论(1编辑  收藏  举报