如何从十六进制颜色字符串中获取颜色 [英] How to get a Color from hexadecimal Color String

查看:26
本文介绍了如何从十六进制颜色字符串中获取颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用诸如 "#FFFF0000" 之类的 hexa 字符串中的颜色来(例如)更改布局的背景颜色.Color.HSVToColor 看起来像一个赢家,但它需要一个 float[] 作为参数.

I'd like to use a color from an hexa string such as "#FFFF0000" to (say) change the background color of a Layout. Color.HSVToColor looks like a winner but it takes a float[] as a parameter.

我接近解决方案了吗?

推荐答案

试试Color类方法:

public static int parseColor (String colorString)

来自 Android 文档:

支持的格式有:#RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', '黑灰色'

Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'

AndroidX:String.toColorInt()

这篇关于如何从十六进制颜色字符串中获取颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆