android - 获取颜色资源作为字符串

标签 android android-xml android-resources

我正在尝试对颜色资源使用 Color.parseColor():

<color name="redish">#FF0000</color>

我试过了,但它给了我错误未知颜色:

Color.parseColor(Integer.toHexString(context.getResources().getColor(R.color.redish)))

如何将颜色资源正确地转换为 String

最佳答案

我想你错过了#

Color.parseColor("#"+Integer.toHexString(ContextCompat.getColor(context, R.color.redish)))

关于android - 获取颜色资源作为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32409964/

相关文章:

android - 将短信标记为已读 android

android - 在 Lollipop 中打开相机时黑屏

android - 以编程方式创建/添加 View 寻呼机

java - 空白布局 - eglSurfaceAttrib 未实现

java - 我如何在 firebase 中自动递增一个值

安卓内部

android - .xml 文件中的 android 和 android2 字段有什么区别?

android - PercentRelativeLayout 百分比值缺少 XML 资源类型?

安卓工作室 : 'name' attribute should be defined

android - Android中 Activity 之外的文本本地化?