我通过继承 DialogFragment 类实现了我自己的 Dialog。
我想更改此默认对话框的背景颜色。
我尝试了几种方法,但似乎都没有。如果您看到下面的 onCreateDialog() 方法,我使用的是自定义对话框样式:
public class ConfirmationDialogFragment extends SherlockDialogFragment {
String mTextMessage = "Would you like to save the message";
String mTextButtonOk = "Ok";
TestDialogInterface dialogInterface = null;
public void setDialogInterface(TestDialogInterface dialogInterface) {
this.dialogInterface = dialogInterface;
}
/**
*/
public ConfirmationDialogFragment() {
}
public void setTextMessage(String mTextMessage) {
this.mTextMessage = mTextMessage;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom));
builder.setMessage(mTextMessage)
.setPositiveButton(mTextButtonOk, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dismiss();
}
})
.setCancelable(false);
builder.setTitle("Loan Extension");
Dialog dialog = builder.create();
return dialog;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
public class TestDialogInterface{
public void onYes(){}
public void onNo(){}
}
}
样式文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AlertDialogCustom" parent="@android:style/Theme.DeviceDefault.Light.Dialog">
<item name="android:windowBackground">@color/red</item>
<item name="android:colorBackground">@color/red</item>
</style>
</resources>
但是 windowBackground 样式项似乎没有效果。我需要更改此默认对话框的背景颜色。
有人有线索吗???