【问题标题】:Dialog full screen layout issue对话框全屏布局问题
【发布时间】:2019-10-22 15:56:28
【问题描述】:

全屏对话框中的布局未正确呈现。

这是我的对话代码:

val mDialogView = LayoutInflater.from(this).inflate(R.layout.alertdialog_info, null)

    val mBuilder = AlertDialog.Builder(this, R.style.FullScreenDialog)
            .setView(mDialogView)

    val mAlertDialog = mBuilder.show()

    mDialogView.titleTv.text = getString(R.string.title)
    mDialogView.descriptionTv.text = getString(R.string.description)

    mAlertDialog.show()

在 style.xml 中,这是我的 FullScreenDialog:

<style name="FullScreenDialog" parent="android:Theme.Dialog">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:windowBackground">@color/md_white_1000</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

这是我的布局:

 <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:tools="http://schemas.android.com/tools"
        android:paddingTop="16dp"
        android:gravity="bottom"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:background="@color/md_white_1000">

                <ImageView
                    android:id="@+id/iconIv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="50dp"
                    android:src="@drawable/ic_success"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintBottom_toTopOf="@id/titleTv" />

                <TextView
                    android:id="@+id/titleTv"
                    style="@style/FontLocalizedBold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    tools:text="@string/payment_success"
                    android:textColor="@color/colorTextPrimary"
                    android:textSize="24sp"
                    android:layout_marginStart="24dp"
                    android:gravity="center"
                    android:layout_marginEnd="24dp"
                    android:maxLines="2"
                    android:layout_marginTop="16dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintBottom_toBottomOf="parent" />


                <TextView
                    android:id="@+id/descriptionTv"
                    style="@style/FontLocalizedMedium"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="24dp"
                    android:layout_marginTop="48dp"
                    android:layout_marginEnd="24dp"
                    android:gravity="center"
                    tools:text="@string/payment_success_description"
                    android:textSize="17sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/titleTv" />

                <TextView
                    android:id="@+id/okTv"
                    style="@style/ButtonTextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginEnd="16dp"
                    android:paddingBottom="16dp"
                    android:background="@drawable/save_button_active"
                    android:text="@string/done"
                    app:layout_constraintBottom_toBottomOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

我尝试过使用 LinearLayout 而不是 ConstraintLayout,但结果相同。

我附上了我的 xml 文件外观的图片,以及它在模拟器上呈现的外观,请忽略不同的字符串值。

模拟器:

xml:

知道什么会导致渲染的差异吗?

【问题讨论】:

  • 您是否选择了您在 XML 编辑器中使用的样式到 FullScreenDialog?如果不是,它将被设置为默认的 AppTheme
  • 我不知道该怎么做
  • 我为您添加了带有图片的答案。希望它有所帮助:-)

标签: android kotlin layout dialog android-constraintlayout


【解决方案1】:

听起来您需要在 xml 查看器中更新预览样式。我突出显示了在当前版本的 AndroidStudio 中使用的下拉框。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    相关资源
    最近更新 更多