gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:14 24 4
gpt4 key购买 nike

我已经在我的 Activity 中以编程方式定义了 TextInputLayout。我在该 TextInputLayout 中添加了 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 中更改单个字母或字母表的提示颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39656596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com