18910140161

在android中如何使用Html渲染的方式实现必填项前面的*号

顺晟科技

2021-06-16 10:29:17

284

一开始我用一个TextView单独加载对应进行测试,发现如果需要改变颜色,那么所有的TextView都需要重新改变颜色。然后我用一个TextView测试把对应关系和对应的文本一起加载,但是发现*符号的高度不好控制,最后觉得Html是更好的渲染方式。话不多说,开始正文。

1.Xml布局(仅选择相应的部分)

这里的*符号和文本实际上共享一个文本视图

线形布局

style=' @ style/style _ match _ line _ layout '

androd : layout _ marginTop=' 10dp '

!——主要看这个TextView——

带边框的

android:id='@ id/tv_nation '

style=' @ style/style _ job _ textview _ text _ title '

工具:文本='*民族'

Android : text=' @ string/tip _ nation '/

相对布局

andro id : id=' @ id/view _ nation '

style=' @ style/style _ job _ textview _ text _ message '

android:clickable=' true '

编辑文本

android:id='@ id/et_nation '

style='@style/style_editext '

Android : hint=' @ string/tip _请_select'/

ImageViewstyle=' @ style/style _ editext _ image _ arrow '/

/RelativeLayout

/LinearLayout

2.创建相应的字符串资源

在这里,您可以分别设置*符号和文本的颜色、加粗等操作

复制代码代码如下:

stringname=' tip _ xinghao _ nation '数据![CData[font color=' # e 60012 ' */font font color=' # 189 DDE '民族:/font]/Data/string

3.用java代码呈现

TVNation . SetText(Html . FrOmHTML(GetString(r . StrIng . tip _ xinhao _ nation));

在这里,你可以实现效果图中的效果。如果更改*符号和文本的颜色和大小,可以在字符串资源中统一更改。

本文转载自中文网站

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航