微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 在TextInputLayout中更改单个字母或字母的提示颜色

我已经在我的Activity中以编程方式定义了TextInputLayout.我已经在TextInputLayout中添加了EditText,以编程方式.

现在,我必须设置该edittext的提示颜色.在这里,我只需要改变提示的单个字母的颜色.

Example - Hint is like, Firstname *. Here  i want to change the color of "*" to Red and remaining hint as black in color.

我已经尝试过Html和Spannable String,但两者都不适用于TextInputLayout.

对于Spannable我做了

SpannableString redSpannable = new SpannableString(red);
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, red.length(), 0);
Spanned hint = Html.fromHtml(string + redSpannable);
etDefault[j].setHint(hint);

对于HTML,

I used "font-color"

如果有人知道这一点,那么分享您的意见.

解决方法:

按照Android Issue Tracker,

Setting the hint to the editText respects the span, but the label does
not float on focus.

editText.setHint(hint);

Setting the hint to the textInputLayout ignores the span

textInputLayout.setHint(hint);

TextInputLayout uses internal class CollapsingTextHelper to draw the
hint, which does not support spans.

正如他们所说,

They have passed this defect on to the development team and will
update this issue with more information as it becomes available.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐