分享

dialog的全透明无边框背景

 杰出天下 2013-01-07

做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>  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多