edittext中相同提示的多个提示或多种样式 [英] Multiple hints or multiple style for the same hint in edittext
问题描述
如何在EditText组件中添加另一个提示,该提示将作为提示进行响应,但默认提示则有所不同.
How to add to an EditText component another hint that will react as an hint, but with different as the default hint.
例如:字段名称是city,所以我希望将黑色的主要提示显示为"city",而将浅蓝色的主要提示显示为轻按以选择城市".
For example: field name is city, so I would like the primary hint in black to be displayed as "city" and in light blue I would like it to be dislayed as "tap to select a city".
是否有任何现成的组件或xml属性? 是在这种情况下,我需要Java代码并实现onfocus并显示/隐藏另一个将作为标签进行响应的TextView吗?
Are there any ready-to-go components or xml attributes for it? Is this a case where I need Java code and implement onfocus and show/hide another TextView that will react as label?
我将其作为strings.xml:
I got this as strings.xml:
<string name="fld_fullname">
<![CDATA[
<font color="#8B8B8B">City</font> <font color="#BABABA">tap to change</font>
]]>
</string>
以及Java代码中的代码:
and this in Java code:
etCity.setHint(Html.fromHtml(getString(R.string.fld_city)));
现在,如何从colors.xml中获取颜色?我可以使用占位符还是有更好的方法? 寻求最佳实践...
Now, how can I take the color from colors.xml? Might I use placeholders or is there a better way? Asking for best practice...
推荐答案
EditText只有一个提示属性,尽管您可以像这样以编程方式添加多色提示
There is only one hint attribute to EditText although you can add multi-colored hint programmatically like this
myEditView.setHint(Html.fromHtml("city - <font color='blue'>tap to select a city</font>."));
如果要从string.xml和color.xml中获取值,请执行以下操作:
if you are taking values from string.xml and color.xml then do following:
myEditView.setHint(Html.fromHtml(getString(R.string.hint1)+" <font color='"+getResources().getColor(R.color.hintColor)+"'>"+getString(R.string.hint2)+"</font>."));
这篇关于edittext中相同提示的多个提示或多种样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!