在TextInputLayout中更改单个字母或字母的提示颜色 [英] In TextInputLayout change the color of hint for single letter or alphabet

查看:144
本文介绍了在TextInputLayout中更改单个字母或字母的提示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Activity中以编程方式定义了TextInputLayout.我已经在TextInputLayout中添加了EditText,以便通过编程方式实现.

I have defined TextInputLayout programmatically in my Activity. I have added EditText inside that TextInputLayout, that to programmatically.

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

Now, I have to set the color of hint of that edittext. Here I just have to change the color of single alphabet of the hint.

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.

I have already tried Html and Spannable String, but both are not working for TextInputLayout.

我做到了跨度

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"

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

If anyone knows this, then share your opinion.

推荐答案

按照

将提示设置为editText会遵守跨度,但是标签会 不能聚焦.

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

editText.setHint(hint);

将提示设置为textInputLayout会忽略跨度

Setting the hint to the textInputLayout ignores the span

textInputLayout.setHint(hint);

TextInputLayout使用内部类CollapsingTextHelper绘制 提示,它不支持跨度.

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.

这篇关于在TextInputLayout中更改单个字母或字母的提示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆