Android 将RGB转换为java中的字符串,将RGB转换成十六进制代码 在我的项目中,我尝试将 RGB 值考虑为一个字符串到 HEX 值。我尝试过下面的代码,但是没有帮助。PLZ.帮助我。

Android 将RGB转换为java中的字符串,将RGB转换成十六进制代码 在我的项目中,我尝试将 RGB 值考虑为一个字符串到 HEX 值。我尝试过下面的代码,但是没有帮助。PLZ.帮助我。,android,Android,String myColorString = "rgb(26,33,37)"; int color = Integer.parseInt(myColorString, 16); int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = (color >> 0) & 0xFF; FooterColor.setBackgrou

    String myColorString = "rgb(26,33,37)";
    int color = Integer.parseInt(myColorString, 16);
    int r = (color >> 16) & 0xFF;
    int g = (color >> 8) & 0xFF;
    int b = (color >> 0) & 0xFF;
    FooterColor.setBackgroundColor(Color.rgb(r, g, b)); 

我建议使用诸如.subString()之类的字符串操作方法 之后采用拆分法。它使用起来很简单

String colrStr="rgb(12,13,14)";
String tempStr=colrStr.substring(4,11);
String rgbArray[]=tempStr.split(",");

如果不是所有的数字都有2个数字,则会断开。直到“rgb”(“它不会改变。所以我们可以使用字符串tempStr=colrStr.substring(4,colrStr.length()-2);我想使用正则表达式会更合适。是的,你可以。我建议另一种方法。在你觉得方便的地方使用它。字符串colrStr=“rgb(45,56,232)”;字符串tempStr=colrStr.substring(4,15);字符串[]rgbarry=tempStr.split(“,”;int r=Integer.parseInt(rgbaray[0]);int g=Integer.parseInt(rgbaray[1]);int b=Integer.parseInt(rgbaray[2]);FooterColor.setBackgroundColor(Color.rgb(r,g,b));字符串中的rgb值是否为十六进制?26、33和37?这些是十六进制值吗?