androidtextviewbackground-color

How to set text color of a TextView programmatically


How can I set the text color of a TextView to #bdbdbd programmatically ?


Solution

  • Use,..

    Color.parseColor("#bdbdbd");
    

    like,

    mTextView.setTextColor(Color.parseColor("#bdbdbd"));
    

    Or if you have defined color code in resource's color.xml file than

    (From API >= 23)

    mTextView.setTextColor(ContextCompat.getColor(context, R.color.<name_of_color>));
    

    (For API < 23)

    mTextView.setTextColor(getResources().getColor(R.color.<name_of_color>));