I want to set the textview color in class1 through the command

textView.setTextColor(Integer.parseInt(class2.font1)); 

font1 is set in class2 like this:

 public static String font1 ="0xff00ffff"; 

but the program crashes, tried so

 int ccc= Integer.valueOf(class2.font1); textView.setTextColor(ccc); 

also flies, maybe someone knows what I'm doing wrong?

    3 answers 3

    If the contents of font1 are aarrggbb color, then try this:

     textView.setTextColor(Color.parseColor(class2.font1)); 

    only replace "0xff00ffff" with "# ff00ffff"

    • Thanks, this option worked - Hellraiser
    • @ user194394 can mark the answer as true (check mark next to the answer). - andreycha Nov.

    Integer.parseInt("ff0000", 16) Where 16 is the digit capacity of a number. For a binary system, for example, you must use 2.

    If there is 0x, you need to use Integer.decode("0x00ff0000");

       int foo = Integer.parseInt("1234");