首页 > 解决方案 > 在android中将颜色而不是图像设置为imageview

问题描述

我有ImageViews显示客户图像的。如果客户的图像不可用,我想在 中显示灰色背景ImageView

编辑:它是来自 'de.hdodenhof:circleimageview:2.2.0' 的 CircleImageview 当我设置背景颜色时,它变成一个矩形而不是圆形。

标签: android

解决方案


如果您使用的是 CircularImageView ,则可以创建一个圆形可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid
        android:color="#808080"
        />

    <size
        android:height="120dp"
        android:width="120dp"
        />
</shape>

然后在客户图像不可用时将其设置为资源。


推荐阅读