我已经在我的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"
如果有人知道这一点,那么分享您的意见.
解决方法:
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.