相关疑难解决方法(0)

在Android 6.0 Marshmallow(API 23)上弃用了getColor(int id)

Resources.getColor(int id)方法已被弃用.

@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException {
    return getColor(id, null);
}
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

android android-resources android-mnc android-6.0-marshmallow

686
推荐指数
12
解决办法
27万
查看次数

创建一个新的颜色drawable

我试图将十六进制值转换为int,以便我可以创建一个新的颜色drawable.我不确定这是否可行,但根据文档,它应该.它显然要求

public ColorDrawable(int color)

在API级别1中添加创建具有指定颜色的新ColorDrawable.

参数 color 要绘制的颜色.

所以,我的代码不起作用,因为我得到一个无效的int:"FF6666"错误.有任何想法吗?

int decode = Integer.decode("FF6666");
ColorDrawable colorDrawable = new ColorDrawable(decode);
Run Code Online (Sandbox Code Playgroud)

java android android-drawable colordrawable

69
推荐指数
4
解决办法
8万
查看次数