8

How can i convert color code in integer ex: 13369395 to android specific. Since 13369395 is also an integer i tried doing

mainLayout.setTextColor(13369395);

but its not working.

I also tried converting 13369395 to hexadecimal like:

mainLayout.setBackgroundColor(Integer.parseInt(13369395 +"", 16)+0xFF000000);

but it also didn't help.

4

4 に答える 4

8

私は解決策を得ました。以下のように16進数で回避するだけです:

Integer.toHexString(colour);

これは、整数の 16 進文字列を返します。

mainLayout.setBackgroundColor(Integer.parseInt(hexVal,16));

それはうまくいきません。次のようにマスクを追加する必要があります

mainLayout.setBackgroundColor(0xff000000 + Integer.parseInt(hexVal,16));

これで問題は解決しました

于 2011-12-14T07:06:56.560 に答える
8

渡してみてください:

mainLayout.setBackgroundColor(Color.parseColor("#FFFFFF"));
于 2016-11-06T09:49:07.297 に答える
-2

16進コードを直接取得できます。たとえば

mainLayout.setBackgroundColor(#0BB5FF);

于 2011-12-13T13:27:58.167 に答える