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>  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM