Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(Android按钮)如何在一个按钮上实现两行不同颜色的文本_Android_Button - Fatal编程技术网

(Android按钮)如何在一个按钮上实现两行不同颜色的文本

(Android按钮)如何在一个按钮上实现两行不同颜色的文本,android,button,Android,Button,在我的android应用程序开发中,我有一个按钮,按钮文本不是单色文本,而是两行文本,每行使用不同的颜色作为行文本。如何实现这一点?“两行”只需在文本中添加“\n”即可实现,我不知道如何为按钮上的每行文本设置不同的颜色。有人可以帮忙吗?在设置按钮文本时,请尝试使用Html.fromHtml: Button button = (Button) getElementById(R.id.some_button); button.setText(Html.fromHtml("<font color

在我的android应用程序开发中,我有一个按钮,按钮文本不是单色文本,而是两行文本,每行使用不同的颜色作为行文本。如何实现这一点?“两行”只需在文本中添加“\n”即可实现,我不知道如何为按钮上的每行文本设置不同的颜色。有人可以帮忙吗?

在设置按钮文本时,请尝试使用Html.fromHtml:

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>"));
Button-Button=(Button)getElementById(R.id.some_按钮);
button.setText(Html.fromHtml(“第一行
第二行”);
嗨,康斯坦丁,谢谢你的回复,事实上我知道你说了什么,但这是一个不推荐使用的HTML标记,这就是为什么我在这里问这个问题。为什么这会困扰你?对于android文本视图,您不需要使用尖端HTML。您还可以尝试使用本谷歌指南动态设置文本样式