如何颜色整数转换为Android的十六进制字符串?整数、转换为、字符串、颜色

由网友(荒芜°)分享简介:我有一个是从一个生成的整数 android.graphics.Color I have a an integer that was generated from an android.graphics.Color该整数有-16776961值The Integer has a value of -16776961...

我有一个是从一个生成的整数 android.graphics.Color

I have a an integer that was generated from an android.graphics.Color

该整数有-16776961值

The Integer has a value of -16776961

我要如何转换这个值转换成十六进制的字符串,格式为#RRGGBB

How do I convert this value into a hex string with the format #RRGGBB

简单地说:我想输出#0000FF从-16776961

Simply put: I would like to output #0000FF from -16776961

注意:我不希望输出包含一个字母,我也尝试过的这个例子中没有任何成功

Note: I do not want the output to contain an alpha and i have also tried this example without any success

推荐答案

面膜可以确保你只能得到RRGGBB,并且%0​​6X给你补零十六进制(总是6个字符长):

The mask makes sure you only get RRGGBB, and the %06X gives you zero-padded hex (always 6 chars long):

String hexColor = String.format("#%06X", (0xFFFFFF & intColor));
阅读全文

相关推荐

最新文章