android - GradientDrawable setStroke 在 Android Lollipop 上不起作用

标签 android graphics drawable android-5.0-lollipop

我在 ImageView 中有一个 Drawable,我正在运行时对其进行修改,以便为用户的排名提供自定义颜色。修改它的方法在低于 20 的 Android 版本上工作正常,但高于它的 drawable 无法一致更新。

有问题的特定方法如下所示:

void setColor(int color) {
    GradientDrawable drawable = (GradientDrawable) mImageView.getDrawable().mutate();
    drawable.setStroke(14, color);
    drawable.invalidateSelf(); // make sure we redraw
}

正如我所说,这在 Android 20 之前工作正常,但在 Android 20 之后,可绘制对象不会添加描边。有新方法还是我忘记了什么?

最佳答案

你应该使 View 无效:

mImageView.invalidate();

关于android - GradientDrawable setStroke 在 Android Lollipop 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29926305/

相关文章:

java - 我如何启动音乐播放器

android - 多语言应用程序中的图像获取问题

R 图形 : output to several file formats

java - 我可以从drawable或assets之外的任何其他文件夹加载文件吗?

android - DrawableCompat.unwrap 在 Lollipop 之前不起作用

android - 如何不覆盖以前的终端内容

c++ - 如何在 Raylib 中用像素追踪路径?

java - jogl 列出所有图形设备

来自外部文件的 Canvas 上的 Android 位图

java - JSON 到 GSON 对象