【问题标题】:BottomSheetDialog not showing?BottomSheetDialog 不显示?
【发布时间】:2016-04-19 15:28:05
【问题描述】:

我正在尝试实现新的 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();

我该如何解决这个问题?

【问题讨论】:

  • 你能在哪里解决这个问题?
  • 在其上显示BottomSheetDialog时不要使用constraintLayout作为根布局...
  • 我们可以检查几个步骤: 1. 使用静态方法 newInstance 2. 尝试将 linearLayoutCompat 作为根布局 3. 尝试彩色背景以获得想法 4. 尝试根布局的 match_parent height 5. 制作确保没有调用关闭或取消 6. 检查可见性 7. 重新启动:PC 和设备

标签: android material-design bottom-sheet


【解决方案1】:

我遇到了这个问题,原因是

  1. 对话框 XML 名称与其他模块 XML 文件名相同,因此请尝试将其重命名为另一个

  2. 检查布局文件,可能有错误,保持最简单的布局测试。

【讨论】:

    【解决方案2】:

    我们可以检查几个步骤:

    1. 创建并使用静态方法newInstance,并对其调用show()方法。
    2. 尝试将LinearLayoutCompat 作为根布局。
    3. 尝试在根布局中使用彩色背景以获得灵感。
    4. 尝试match_parent 高度作为根布局。
    5. 确保没有立即调用 dismiss()cancel()
    6. 检查可见性。
    7. 同时重启:PC 和设备。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      相关资源
      最近更新 更多