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.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...