android - 如何修复底部工作表对话框的出现位置
问题描述
在 Android 11 中,BottomSheetDialog
(BSD) 看起来像它应该的那样,但在旧版本上它要么在它上面,要么Navigation Bar
在它下面。我附上了我的问题的图片,这是我的 xml:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/modal_bottom_sheet_background"
android:backgroundTint="?attr/backgroundColor"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_gravity="bottom"
app:layout_behavior="android.support.design.widget.BottomSheetBehaviorvior"
>
<androidx.cardview.widget.CardView
android:id="@+id/fab_tabliceID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/layout_container_margin_start_end_16"
android:layout_marginTop="32dp"
android:layout_marginEnd="@dimen/layout_container_margin_start_end_16"
app:cardCornerRadius="@dimen/card_corner_radius_15"
app:layout_constraintTop_toTopOf="parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="8dp"...
这是当我试图将所有内容都包含在 Coordinator Layout 中时,但它没有用:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/modal_bottom_sheet_background"
android:backgroundTint="?attr/backgroundColor"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<!--android:background="@android:color/transparent"-->
<!--android:layout_gravity="bottom"-->
<androidx.cardview.widget.CardView
android:id="@+id/fab_tabliceID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/layout_container_margin_start_end_16"
android:layout_marginTop="32dp"
android:layout_marginEnd="@dimen/layout_container_margin_start_end_16"
app:cardCornerRadius="@dimen/card_corner_radius_15"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"...
当然,我想到的解决方案之一是在代码中检查 Android 版本,然后,如果需要,添加底部边距,但这看起来不是正确的方法。
解决方案
推荐阅读
- wavesplatform - 从 Waves Exchange 获取我的加密货币的市场价值
- google-analytics - GA 衡量协议:尽管使用 SubID 发送了太多目标,但最终还是“直接”
- java - 为什么以下问题的所有测试用例都没有通过?
- spring - 将字符串从方面传递到 JointPoint
- php - Laravel - 从数据透视表中获取额外的列值
- python-3.x - 尝试使用 pytorch 训练神经网络时,“AttributeError:classificadorFinal”对象没有属性“log_softmax”
- php - Symfony 翻译:更新实体注释
- javascript - 如何将 JS 变量(来自 EOD 标记嵌入脚本)从同一个 PHP 文件中传递回 PHP?
- java - 从字节/帧 Java/Android 创建可播放的视频流
- docker - 使用动态值永久更改 Dockerfile 中的 PATH