Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Android button) how to implement Two line text with different colors on one button

Tags:

android

button

In my android app development, I have one button, the button text is not a single color text, it is two lines text, with each line uses different color for line text. How to implement this? "Two lines" can be simply implemented by adding "\n" in the text, I don know how to set different colors for each line text on the button. Anyone can help?

like image 343
Mellon Avatar asked Dec 02 '25 20:12

Mellon


1 Answers

Try to use Html.fromHtml when setting text to a button:

Button button = (Button) getElementById(R.id.some_button);
button.setText(Html.fromHtml("<font color='red'>First line</font><br/><font color='blue'>Second line</font>"));
like image 183
Konstantin Burov Avatar answered Dec 04 '25 10:12

Konstantin Burov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!