开发者

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

开发者 https://www.devze.com 2023-01-26 22:58 出处:网络
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 line

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?


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>"));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号