我在尝试实现dialogfragment的自定义标题时遇到了这个异常
requestFeature() must be called before adding content
stackoverflow上有很多关于此问题的线程,但问题是我真的不知道如何实现这个函数调用以及在哪里放置它?
我试图将它放在片段回调onCreate()中,但它根本不起作用。
那么我应该如何使用并放置此功能呢?例如 - 如果我为我的片段创建了自定义标题 - 在调用requestFeature时使用以下标志是否正确:
Window.FEATURE_CUSTOM_TITLE
public static class ImageExtrasFragment extends DialogFragment {
private View theView;
@Override
public void onCreate(Bundle savedInstanceState) {
getActivity().getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
//views
theView = factory.inflate(R.layout.tex_timage, null);
imgView = (ImageView) theView.findViewById(R.id.text_img);
imgView.setImageBitmap(bitmap);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.fragmenttitle, null);
TextView titleView = (TextView) dialogView.findViewById(R.id.fragment_title);
titleView.setText(title);
builder.setView(dialogView);
return builder.create();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return theView;
}
}