Android setting text view color from java code

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

    You Can also use text.setTextColor(0xFFF06D2F);
    but not just text.setTextColor(0xF06D2F);

    0 讨论(0)
  • 2021-02-07 07:15
    textview.setTextColor(ContextCompat.getColor(context, R.color.your_color));
    
    0 讨论(0)
  • 2021-02-07 07:15

    If you want to change your Text Color and take value from values/colors.xml If statement is holding text color for higher api because else version is depreciated in api23

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 
    {
    textview_name.setTextColor(getColor(R.color.your_color_name));
    }
    else
    {               textview_name.setTextColor(getResources().getColor(R.color.your_color_name));
    }
    
    0 讨论(0)
提交回复
热议问题