BottomSheetDialog没有显示?

8

我正在尝试实现新的BottomSheetDialog,但是当我调用.show()方法时,它显示了背景阴影但不显示我的布局。

这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="4dp"
            android:paddingBottom="4dp"
            android:paddingStart="8dp"
            android:paddingEnd="8dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Notes"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:textColor="@android:color/black"/>

            <Switch
                android:id="@+id/notes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_alignParentEnd="true"/>

        </RelativeLayout>

    </RelativeLayout>

</android.support.v4.widget.NestedScrollView>

然后:
    mSettingsDialog = new BottomSheetDialog(this);
    View v = getLayoutInflater().inflate(R.layout.reader_settings,  null);
    mSettingsDialog.setContentView(v);
    mSettingsDialog.show();

我如何解决这个问题?


你修复好这个问题了吗? - channae
在显示BottomSheetDialog时,不要将constraintLayout用作根布局... - Sagar Patel
我们可以采取以下几个步骤进行检查:
  1. 使用静态方法newInstance
  2. 尝试使用linearLayoutCompat作为根布局
  3. 尝试使用彩色背景以获取想法
  4. 尝试将根布局的高度设置为match_parent
  5. 确保没有调用dismiss或cancel
  6. 检查可见性
  7. 重新启动PC和设备
- Sagar Patel
2个回答

2
我遇到了这个问题,原因是:
  1. 对话框 XML 文件名称与其他模块的 XML 文件名称相同,因此尝试将其重命名为另一个名称。

  2. 检查布局文件,可能存在一些错误,请保持简单测试最简单的布局。


0

我们可以检查以下几个步骤:

  1. 创建并使用静态方法 newInstance,并在其上调用 show() 方法。
  2. 尝试将 LinearLayoutCompat 作为根布局。
  3. 尝试为根布局设置彩色背景以获得想法。
  4. 尝试将根布局的高度设置为 match_parent
  5. 确保不立即调用 dismiss()cancel()
  6. 检查可见性。
  7. 如果它包含一个 recyclerView,请确保它有项目,getItemCount 不返回0,并且我们正确设置了值!
  8. 重新启动电脑和设备。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接