【发布时间】:2021-04-05 04:37:40
【问题描述】:
我的自定义警报对话框发生了一件非常奇怪的事情。相同的代码在不同的时间运行时,会产生不同的警报对话框布局的背景颜色,其中大多数时候颜色是红色(无处不在!),即使我对布局使用了不同的背景。先看看我的代码。
这是 AlertDialog 的布局(layout_add_url.xml)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_margin="@dimen/_10sdp"
android:id="@+id/url_layout_constraint"
android:background="@drawable/background_note"
android:layout_height="wrap_content">
//Some ImageViews and TextViews here
这就是layout_add_url.xml终于有了
现在,
这是 background_note.xml
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#333333"/> //Note that the color here is black
<corners android:radius="@dimen/_10sdp"/>
</shape>
这是我最终在 Kotlin Activity 中创建 AlertDialog 的地方
val inflater = layoutInflater
val view = inflater.inflate(R.layout.layout_add_url, null)
val infoDialogBuilder = AlertDialog.Builder(this@CreateNotesActivity)
infoDialogBuilder.setView(view)
val infoDialog = infoDialogBuilder.create()
infoDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
infoDialog.setContentView(view)
infoDialog.show()
但是在真实设备上运行项目之后。看起来像这样
注意
我注意到,当我将 android:background="@drawable/background_note" 更改为 android:background="#333333" 时,代码似乎工作正常
【问题讨论】:
标签: android kotlin popup window