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

In my Android application development, I have one button, the button text is not one colored text, it is two-line text, and each line uses a different color for the text of the line. How to implement this? "Two lines" can simply be implemented by adding "\ n" to the text, I don’t know how to set different colors for each line text on the button. Who can help?

+3
source share
1 answer

Try using Html.fromHtml when customizing the text on the 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>"));
+8
source

Source: https://habr.com/ru/post/1776698/


All Articles