在使用Dialog的时候,我们发现Dialog有一个构造方法Dialog(Context context,int themeResId),里面可以指定一个主题样式,下面我们就试试捣腾一下吧.因为Dialog需要setContentView的,所以我们偷个懒,先使用AlertDialog去玩玩.
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.custom_dialog);
builder.setTitle("提示信息:");
builder.setMessage("你好呀!");
builder.create().show();
styles.xml添加下面样式
<style name="custom_dialog" parent="android:style/Theme.Dialog">
</style>
这时效果是这样的,好丑,我们把边边的背景去掉
<style name="custom_dialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
这时候就没有了背景了,只有需要显示的内容了.虽然还是很丑,但是我们会在下一篇文章结合之前的知识去做一个好看的ProgressDialog