我正在尝试在 DialogFragment 中实现 ProgressDialog 并将其用作 fragment 。我的 onCreateDialog 看起来像这样:
public Dialog onCreateDialog(Bundle savedInstanceState) {
String message = getArguments().getString("msg");
ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setMessage(message);
dialog.setTitle("");
dialog.setCancelable(true);
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
return dialog;
}
根据 Android 开发人员的说法,要将此对话框用作 Fragment,我必须实现 onCreateView,它返回 View 对象。问题是,如何获取此类对话框的 View ?
最佳答案
它仅适用于 onCreateDialog。 如果您想创建更复杂的 View 和 fragment ,您应该创建一个方法,例如:
public View onCreateView( . .. ) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.fragment_xml_id, null);
return view;
}
请参阅此博客了解更多信息: http://android-developers.blogspot.com/2012/05/using-dialogfragments.html
关于android - 获取默认对话框的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10470174/