Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 创建圆形自定义警报对话框:着色区域不正确_Android_Android Layout - Fatal编程技术网

Android 创建圆形自定义警报对话框:着色区域不正确

Android 创建圆形自定义警报对话框:着色区域不正确,android,android-layout,Android,Android Layout,我已成功尝试使用以下代码创建自定义警报对话框。但是,当我试图使custom_dialog.xml中的约束布局具有圆角时,它显示了一个错误:由于圆角,黑色变暗/着色区域没有覆盖白色区域。这就是我要说的: MainActivity.kt的我的代码: 自定义_dialog.xml的我的代码: 如何删除对话框周围的白色区域?您可以轻松提供自己的样式: <style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">

我已成功尝试使用以下代码创建自定义警报对话框。但是,当我试图使custom_dialog.xml中的约束布局具有圆角时,它显示了一个错误:由于圆角,黑色变暗/着色区域没有覆盖白色区域。这就是我要说的:

MainActivity.kt的我的代码:

自定义_dialog.xml的我的代码:


如何删除对话框周围的白色区域?

您可以轻松提供自己的样式:

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">@color/transparent</item>
</style>

我也有同样的问题。使背景透明可以解决这个问题

<style name="Theme_Dialog" parent="Theme.AppCompat.Light.Dialog">

  <item name="android:background">@android:color/transparent</item>
</style>
不确定您的@可拉伸/圆角。相反,您可以使用卡片视图,并将此约束布局放置在卡片视图中。使用app:cardCornerRadius=@dimen/space18,您已根据需要设置半径

<androidx.cardview.widget.CardView 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_height="match_parent"
xmlns:toots="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/white_color"
app:cardCornerRadius="@dimen/space_18">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  ..

</androidx.constraintlayout.widget.ConstraintLayout>
看看这个。您不需要在ConstraintLayout中将@drawable/rounded_角定义为背景
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">@color/transparent</item>
</style>
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme)
        ...
        .create();
<style name="Theme_Dialog" parent="Theme.AppCompat.Light.Dialog">

  <item name="android:background">@android:color/transparent</item>
</style>
val dialog = Dialog(context, R.style.Theme_Dialog)
<androidx.cardview.widget.CardView 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_height="match_parent"
xmlns:toots="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/white_color"
app:cardCornerRadius="@dimen/space_18">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  ..

</androidx.constraintlayout.widget.ConstraintLayout>