DialogFragment fullscreen shows padding on sides

后端 未结 11 1597
囚心锁ツ
囚心锁ツ 2020-12-05 00:22

I am creating a custom DialogFragment that is displayed underneath the actionbar. So far everything works great. The layout parameters for dialog fragment are match_pa

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 00:36

    I met the issue before: there is always a padding while having set fullscreen. try this code in dialogFragment's onActivityCreated() method:

    public void onActivityCreated(Bundle savedInstanceState)
    {   
        Window window = getDialog().getWindow();
        LayoutParams attributes = window.getAttributes();
        //must setBackgroundDrawable(TRANSPARENT) in onActivityCreated()
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        if (needFullScreen)
        {
            window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        }
    }
    

提交回复
热议问题