Tag: inflate

DialogFragment的自定义布局OnCreateView与OnCreateDialog

我试图创build一个DialogFragment使用我自己的布局。 我见过几种不同的方法。 有时候,布局是这样设置的OnCreateDialog :(我使用单声道,但我已经习惯了Java) public override Android.App.Dialog OnCreateDialog (Bundle savedInstanceState) { base.OnCreateDialog(savedInstanceState); AlertDialog.Builder b = new AlertDialog.Builder(Activity); //blah blah blah LayoutInflater i = Activity.LayoutInflater; b.SetView(i.Inflate(Resource.Layout.frag_SelectCase, null)); return b.Create(); } 这第一种方法适用于我…直到我想使用findViewByID. 所以经过一番search后,我尝试了第二种方法,其中涉及覆盖OnCreateView 所以我注释了两行OnCreateDialog ,它们设置了Layout,然后添加了这个: public override Android.Views.View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.Inflate(Resource.Layout.frag_SelectCase, container, false); //should be able to use […]

在DialogFragment中为AlertDialog夸大自定义视图的问题

我正在尝试在DialogFragment使用自定义视图创build一个AlertDialog 。 这个视图必须从xml中夸大。 在我的DialogFragment类中,我有: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setTitle("Title") .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, null)) .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, null) .create(); } 我已经尝试其他通胀方法.setView()如: .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, (ViewGroup) getView(), false)) 和 .setView(getActivity().getLayoutInflater().inflate(R.layout.dialog, (ViewGroup) getTargetFragment().getView(), false)) 在显示此对话框的片段中设置目标片段之后。 所有这些尝试膨胀我的自定义视图结果在以下例外: E/AndroidRuntime(32352): android.util.AndroidRuntimeException: requestFeature() must be called before adding content E/AndroidRuntime(32352): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:214) E/AndroidRuntime(32352): at com.android.internal.app.AlertController.installContent(AlertController.java:248) E/AndroidRuntime(32352): at android.app.AlertDialog.onCreate(AlertDialog.java:314) E/AndroidRuntime(32352): at android.app.Dialog.dispatchOnCreate(Dialog.java:335) […]