ViewPager in DialogFragment - IllegalStateException: Fragment does not have a view

后端 未结 4 1715
渐次进展
渐次进展 2020-12-08 07:24

What I want to achieve

  • From a FragmentActivity show a dialog when clicking an Action Button in the Action Bar
  • DialogFragment
4条回答
  •  臣服心动
    2020-12-08 08:01

    Thanks to @Tommy Visic for writing a really good description it worked.

    Posting the code which worked for me.

    I have removed the Dialog building code from the onCreateDialog method infact removed onCreateDialog method and the dialog view which I have been implementing in the Dialog's custom view I have included it as a View in the onCreateView method and all the things started working.

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.login_sigup_screen, null, false);
        bind = ButterKnife.bind(this, view);
        initViewPager();
        return view;
    }
    

    Faced one more problem with this implementation is:

    When a Activity has Toolbar/ActionBar then it is also displayed into the DialogFragment to avoid that what is to be done is: Implement onViewCreated method of Fragment and add below code

    Dialog dialog = getDialog();
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    float dimAmount = 0.6f;
    dialog.getWindow().setDimAmount(dimAmount);
    

    This will remove the Toolbar from the DialogFragment and Activity will be displayed as it is.

    Cheers

    Thanks @Tommy

    Regards Zeus

提交回复
热议问题