`

对话框,去白边

 
阅读更多

1.

res/values/styles.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="dialog" parent="@android:style/Theme.Dialog"><!--name是我们在使用时要用到的资源的标志,parent是指当前的样式所继承的父类样式-->
         <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowNoTitle">true</item><!--隐藏标题栏-->
        <item name="android:background">@color/trans</item>
        <item name="android:windowBackground">@color/trans</item><!--这儿也很重要啊,我这儿用了一张透明的.9.png的图,当然用#00000000也是可以的,否则的话这儿出来后有一个黑色的背景-->
        <item name="android:backgroundDimEnabled">true</item><!-- 这个属性设置的是对话框是否带有半透明效果,true表示有,如果是false的话就类似popupwindow -->
    </style>
</resources>

 

 

2.res/values/color.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="trans">#00000000</color><!-- 透明的 -->
</resources>

 

3.代码中

 

Dialog myDialog = new Dialog(this, R.style.dialog);//加载属性
  myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  LayoutInflater inflater = ((Activity) context).getLayoutInflater();
  View layout = inflater.inflate(R.layout.choose_dialog, null);
  myDialog.setContentView(layout);
  myDialog.setCanceledOnTouchOutside(true);//触摸对话框外部,对话框消失
  myDialog.show();

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics