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