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

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

概述我已经在我的Activity中以编程方式定义了TextInputLayout.我已经在TextInputLayout中添加了EditText,以编程方式.现在,我必须设置该edittext的提示颜色.在这里,我只需要改变提示的单个字母的颜色.Example-Hintislike,Firstname*.Hereiwanttochangethecolorof"*"

我已经在我的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 – 在TextInputLayout中更改单个字母或字母的提示颜色全部内容,希望文章能够帮你解决android – 在TextInputLayout中更改单个字母或字母的提示颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115786.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存