我已经显示了一个对话框片段。我已经做到了,但我想将背景(主题)颜色灰色更改为白色。如何更改默认片段对话框的主题颜色
我的对话框代码:
public class TestDialog extends DialogFragment {
public static TestDialog newInstance() {
return new TestDialog();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return container;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dailog_fragment, null))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
TestDialog.this.getDialog().cancel();
}
});
return builder.create();
}
}
我做同样的事情,但它不工作... – hharry
你设置'的setStyle(DialogFragment.STYLE_NO_TITLE,R.style.MyDialog) ;'在OnCreate'中? –
是的,我在onCreate中设置了这个方法... – hharry