我有一个DialogFragment:
public static class CharacteristicDialog extends DialogFragment { int mNum; static CharacteristicDialog newInstance(int num) { CharacteristicDialog f = new CharacteristicDialog(); Bundle args = new Bundle(); args.putInt("num",num); f.setArguments(args); return f; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mNum = getArguments().getInt("num"); setStyle(STYLE_NO_INPUT,0); } @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { View v = inflater.inflate(R.layout.characteristic_dialog,container,false); v.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); }
我在我的主片段中创建它,如下所示:
DialogFragment newFragment = CharacteristicDialog.newInstance(v.getId()); newFragment.setShowsDialog(true); newFragment.show(getFragmentManager(),"dialog");
它显示得很好,但它不是模态的(我可以点击两侧并在对话框后面的主片段上进行操作).
我如何制作模态?
谢谢
解决方法
只需将STYLE_NO_INPUTт®STYLE_NORMAL更改为setStyle()方法即可.
有关DialogFragment样式和主题的更多信息,请查看文档:
http://developer.android.com/reference/android/app/DialogFragment.html
有关DialogFragment样式和主题的更多信息,请查看文档:
http://developer.android.com/reference/android/app/DialogFragment.html