Android setting text view color from java code

前端 未结 9 1311
一个人的身影
一个人的身影 2021-02-07 06:43

I have a list and i write a custom adapter for this. And I want to set some text color for this (e.g. Orange color code #F06D2F). I am presenting the code snippet for my g

9条回答
  •  情深已故
    2021-02-07 07:11

    This worked for me, and it is simple. First, import "Color"

    import android.graphics.Color;
    

    Then all you have to do is this:

    text.setTextColor(Color.RED);
    

    Just discovered this today (9/20/13). You can go ahead and declare a variable like this:

    private final int ORANGE = 0xFFFF3300;
    

    Then all you have to do is:

    text.setTextColor(ORANGE);
    

    Note that the first two hex characters are for opacity ("FF" means opaque). Then, in the example above, the second "FF" is for red, then "33" is for green, and "00" is for blue. Should be possible to create a great many colors this way.

    I am pretty new at this Android programming - this is my first post to this forum. Thanks to all of you for your contributions!

提交回复
热议问题