我想創建一個AlertDialog,其中包含一個下一個和一個關閉按鈕,併爲「不再顯示」複選框。我使用DialogFragment的支持庫。下面的代碼只是工作正常,但我想用我自己的XML佈局此AlertDialog:Android在DialogFragment中創建一個自定義AlertDialog
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("num");
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("ASDASDAS")
.setPositiveButton(R.string.hello_world,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
((MainActivity)getActivity()).doPositiveClick();
}
}
)
.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
((MainActivity)getActivity()).doNegativeClick();
}
}
);
return builder.create();
}
是否有可能使用自己的XML佈局創建此AlertDialog?在R.layout.your_custom_dlg
<style name="IconsDialog" parent="@android:style/Theme.Dialog">
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowBackground">@drawable/icons_dlg_bg</item>
<item name="android:windowNoTitle">true</item>
</style>
設置自定義警報佈局:
看看這個 http://stackoverflow.com/questions/2795300/how-to-implement-a-custom-alertdialog-view –