I have a button created in my class Main
via code, that is, programmatically. See:
Button btnJonSnow = new Button(this);
btnJonSnow.setText("Jon Snow");
How can I set the color of the button text programmatically?
I have a button created in my class Main
via code, that is, programmatically. See:
Button btnJonSnow = new Button(this);
btnJonSnow.setText("Jon Snow");
How can I set the color of the button text programmatically?
To set a color for the button text, you must use the setTextColor()
attribute. Soon to redeem the color you can use the static method getColor()
of the public class ContextCompat . Here's an example:
Button btnJonSnow = new Button(this);
btnJonSnow.setText("Jon Snow");
btnJonSnow.setTextColor(ContextCompat.getColor(mContext, R.color.colorAccent));