本文介绍了如何颜色整数转换为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

我要如何转换这个值转换成十六进制的字符串,格式为#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));

这篇关于如何颜色整数转换为Android的十六进制字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 09:26