android将图标添加到自定义警报对话框的边缘

问题描述

我想在我的自定义警报对话框中添加一个图标

我希望将其添加到与下图相同的对话框的边缘。

那我该怎么实现

Alert dialog

//copy the grid into h.
            for(int x = 0; x< 9; x++){
                for(int y =0; y< 9; y++){
                    h[x][y] = grid[x][y];
                }
            }

解决方法

你应该使用圆形图像视图

  1. implement //圆形图像 实现“com.makeramen:roundedimageview:2.3.0”

2.添加此代码

<?xml version="1.0" encoding="utf-8"?>

    <com.makeramen.roundedimageview.RoundedImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="10dp"
        android:elevation="2dp"
        android:background="@drawable/grey_circle"
        android:layout_centerHorizontal="true"/>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:background="@drawable/rounded_white_rectangle"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_marginTop="80dp">
        <TextView
            android:layout_marginTop="30dp"
            android:textColor="@color/blue_dark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Warning"
            android:textStyle="bold"
            android:textAlignment="center"
            android:textSize="40dp"/>

        <TextView
            android:layout_marginTop="30dp"
            android:textColor="@color/blue_dark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="You just display this"
            android:textAlignment="center"
            android:textSize="40dp"/>
        
        <Button
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:text="Done"
            android:layout_marginStart="30dp"
            android:layout_marginEnd="30dp"
            android:textSize="40dp"
            android:textColor="white"/>

    </LinearLayout>

</RelativeLayout>

我将在回放中添加第 3 步