自定义Dialog

来源:互联网 发布:软件培训公司 编辑:程序博客网 时间:2024/04/30 03:58

自定义Dialog,布局文件xml用setContentView(R.layout.logindialog)记载。

遇到的问题:Dialog最上端默认有标题,无论设置,自定义的布局都不能占据整个窗体,

翻遍所有网络资料,都没解决问题。得一同事指点,终于解决问题,分享下:

其实很简单,就一行代码:

mInfoDlg=new Dialog(this,R.style.dialog);//实例化的时候,带一个样式进去,把title去掉

 

R.style.dialog:

<style name="dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
 </style>

 

定义加载到Dialog中的自定义布局的背景,貌似按照一般的方法:直接定义背景色,效果不是想要的。

后来使用渐变设置背景,O了。

<?xml version="1.0" encoding="UTF-8"?>
<shape
  xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="5.0dip" android:topLeftRadius="5.0dip" android:topRightRadius="5.0dip" android:bottomLeftRadius="5.0dip" android:bottomRightRadius="5.0dip" />
    <gradient android:startColor="#ff2596ce" android:endColor="#ff2596ce" android:angle="270.0" android:centerY="0.75" android:centerColor="#ff2596ce" />
</shape>

 

.......................................问题解决,异常开心....................................................................

参考文章:http://www.aslibra.com/blog/post/android-dialog-no-title.php

原创粉丝点击