【问题标题】:DialogFragment in Nougat 7 has strange behavior in full screenNougat 7 中的 DialogFragment 在全屏时有奇怪的行为
【发布时间】:2017-01-31 12:34:14
【问题描述】:

我有一个全屏 DialogFragment。一切都很顺利,直到我使用新的 android Nougat (7) 版本测试了我的应用程序。突然我注意到屏幕顶部和底部出现了奇怪的边距。

父布局是ConstraintLayout,但即使我尝试将其更改为LinearLayout或RelativLayout,也没有任何反应。

我有这个代码行:

getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);  
getDialog().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getDialog().getWindow().setLayout(getScreenWidth(), getScreenHeight());

这是截图:

有什么想法吗?

【问题讨论】:

  • 你好 MorH,我面临着类似的问题。你能告诉我你申请了什么修复来让它工作吗?谢谢
  • 你好,很抱歉耽搁了,但我还是会为大家发布..

标签: android dialog android-dialogfragment android-7.0-nougat android-7.1-nougat


【解决方案1】:

我对此问题的解决方案是将“DialogFragment”添加为“Fragment”而不是对话框。

我删除了:

 dialog.show(fm, MyDialog.class.getSimpleName());

并添加了以下代码:

        FragmentTransaction transaction = iFm.beginTransaction();
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ViewGroup root = (ViewGroup) iActivity.findViewById(android.R.id.content).getRootView();
        FrameLayout child = new FrameLayout(iActivity);
        child.setLayoutParams(new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        child.setId(R.id.dialog_container);
        root.addView(child);
        transaction.add(child.getId(), iDialog).addToBackStack(iDialog.getClass().getSimpleName()).commit();

我在对话框之类的所有内容之上添加了 DialogFragment,但使用了简单的片段事务。 这是我能想到的唯一解决方法,并且到目前为止它工作正常,就像魅力一样:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多