1、通过使用theme
AlertDialog.Builder builder = new Builder(new ContextThemeWrapper(_this,R.style.dialog_pwd));
确保我们创建的对话框是Dialog还是AlertDialog。因为会导致setView的方法出现不同。
AlertDialog是由dialog.setView(view,0,0,0,0);
Dialog时为dialog.setView(view);
例如:
首先定义style文件:
<style name="Theme_Transparent" parent="@android:Theme.DeviceDefault.Light.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
</style>然后java代码中:
AlertDialog.Builder builder = new Builder(new ContextThemeWrapper(_this, R.style.Theme_Transparent));
dialog = builder.create();
LayoutInflater inflater = (LayoutInflater) _this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.activity_change_pwd, null);
dialog.setView(view,0,0,0,0);
本文详细介绍了如何使用theme属性来创建具有透明背景的对话框,并提供了样式定义和Java代码实现步骤。
7707

被折叠的 条评论
为什么被折叠?



