本文介绍了在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.

推荐答案

按照 Android问题跟踪器

editText.setHint(hint);
textInputLayout.setHint(hint);

正如他们所说,

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

08-29 04:22
查看更多