Android setting text view color from java code

前端 未结 9 1307
一个人的身影
一个人的身影 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 06:51

    try like this , the following worked fine for me

    textview.setTextColor(this.getResources().getColor(R.color.orange));
    
    0 讨论(0)
  • 2021-02-07 06:51

    Yes, You can try this

    textview.setTextColor(this.getResources().getColor(R.color.orange));
    
    0 讨论(0)
  • 2021-02-07 06:52

    For Kotlin just use holder.text.setTextColor(Color.RED);

    0 讨论(0)
  • 2021-02-07 06:54

    This is what worked for me.

    Import first: import android.graphics.Color;

    Then you can use: textview.setTextColor(Color.BLUE);

    0 讨论(0)
  • 2021-02-07 06:56
    text.setTextColor(Color.parseColor("#FFFFFF"));
    
    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题