How can I programmatically change the text color of a TextView in an Android app?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our W3Make Forum to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
For programmatically changing the text color of a TextView in Android Studio, you can use the setTextColor() function, which works for me every time
Example:
TextView textView = findViewById(R.id.your_textview_id_name);
textView.setTextColor(Color.BLUE); //for a direct color setting
textView.setTextColor(getResources().getColor(R.color.your_color); //if you want to use another color resource
you can use the setTextColor() method. Here’s an example:
TextView textView = findViewById(R.id.myTextView);
textView.setTextColor(getResources().getColor(R.color.myColor));
or you can also use the setTextColor()
textView.setTextColor(Color.RED);