一、僅更改彈窗的顯示內容android
View view = View.inflate(this, R.layout.**, null);ide
new AlertDialog.Builder(this).setView(view);ui
二、更改彈窗的背景this
若是使用AlertDialog的setView,彈窗的周邊會有黑邊出現,這時候則須要這麼作spa
- Dialog dialog = new Dialog(this, R.style.dialog_style);
- View view = View.inflate(this, R.layout.**, null);
- dialog.setContentView(view);
- dialog.show();
- dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); //自適應大小
dialog_style:xml
- <style name = "dialog_style" parent="@android:style/Theme.Dialog">
- <item name = "android:windowBackground">@drawable/dialog_bg</item>
- <item name = "android:windowNoTitle">true</item>
- </style>
dialog_bg:utf-8
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <solid android:color="#00000000"/>
- </shape>
dialog_bg 用於去掉黑色邊,View中設置好須要的背景.get
三、若是使用AlertDialogit
AlertDialog dialog = AlertDialog.Builder(this).create();io
dialog.show();
Window = dialog.getWindow();
view.setContentView(R.layout.**);
使用這種方法能夠達到背景更換的效果,可是若是添加了EditText會出現,EditText不能彈出輸入法的問題?