多彩多姿的edittext提示 [英] Multicolored edittext hint
本文介绍了多彩多姿的edittext提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当被android.support.design.widget.TextInputLayout包裹时,是否有一种方法可以为edittext的提示设置多种颜色,而不会影响浮动edittext的行为?
Is there a way to set multiple colors to the edittext's hint when wrapped by android.support.design.widget.TextInputLayout without compromising the behaviour of floating edittexts?
喜欢, 标题*
标题和*带有不同的彩色提示
Headline and * with different colored hint
推荐答案
尝试一下!如果要将其用于setText,只需添加BufferType.SPANNABLE(请参见下文)
Try this! If you want to use it for setText just add BufferType.SPANNABLE (see below)
String redPart = "Hello";
String bluePart = "World";
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString redColoredString= new SpannableString(redPart);
redColoredString.setSpan(new ForegroundColorSpan(Color.RED), 0, redPart.length(), 0);
builder.append(redColoredString);
SpannableString blueColoredString= new SpannableString(bluePart);
blueColoredString.setSpan(new ForegroundColorSpan(Color.BLUE), 0, bluePart.length(), 0);
builder.append(blueColoredString);
myEditText.setHint(builder)
//do following for setText
myEditText.setText(builder,BufferType.SPANNABLE)
这篇关于多彩多姿的edittext提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文