我想为不同的字体样式提示和字体样式在edittext文本中输入。 例如。可以说,提示字体大小是12和它的正常类型。但是当用户开始在edittext中输入时,输入文本的字体大小应该变为14并且粗体。再次如果用户删除文本提示应该是上述类型。不同的提示字体样式和键入的文本字体样式android
6
A
回答
4
您可以以编程方式更改提示颜色,使其通过使用下面的代码
editTextId.setHintTextColor(Color.alpha(006666));
0
已经给出的答案是正确的,但目前指定不同的颜色可能也是在在EditText上输入字体样式不同XML文件通过android:textColorHint属性。举例来说,你可以做这样的事情(假设你已经正确定义my_favourite_colour作为一种资源):
<EditText
... other properties here ...
android:textColorHint="@color/my_favourite_colour"
</EditText>
0
可以使用SpannableString
和MetricAffectingSpan
实现它。您将可以更改提示的字体,大小和样式。
1)创建自定义Hint
对象:
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.MetricAffectingSpan;
public class CustomHint extends SpannableString
{
public CustomHint(final CharSequence source, final int style)
{
this(null, source, style, null);
}
public CustomHint(final CharSequence source, final Float size)
{
this(null, source, size);
}
public CustomHint(final CharSequence source, final int style, final Float size)
{
this(null, source, style, size);
}
public CustomHint(final Typeface typeface, final CharSequence source, final int style)
{
this(typeface, source, style, null);
}
public CustomHint(final Typeface typeface, final CharSequence source, final Float size)
{
this(typeface, source, null, size);
}
public CustomHint(final Typeface typeface, final CharSequence source, final Integer style, final Float size)
{
super(source);
MetricAffectingSpan typefaceSpan = new CustomMetricAffectingSpan(typeface, style, size);
setSpan(typefaceSpan, 0, source.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
2)创建的自定义对象MetricAffectingSpan
:
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;
public class CustomMetricAffectingSpan extends MetricAffectingSpan
{
private final Typeface _typeface;
private final Float _newSize;
private final Integer _newStyle;
public CustomMetricAffectingSpan(Float size)
{
this(null, null, size);
}
public CustomMetricAffectingSpan(Float size, Integer style)
{
this(null, style, size);
}
public CustomMetricAffectingSpan(Typeface type, Integer style, Float size)
{
this._typeface = type;
this._newStyle = style;
this._newSize = size;
}
@Override
public void updateDrawState(TextPaint ds)
{
applyNewSize(ds);
}
@Override
public void updateMeasureState(TextPaint paint)
{
applyNewSize(paint);
}
private void applyNewSize(TextPaint paint)
{
if (this._newStyle != null)
paint.setTypeface(Typeface.create(this._typeface, this._newStyle));
else
paint.setTypeface(this._typeface);
if (this._newSize != null)
paint.setTextSize(this._newSize);
}
}
3)使用:
Typeface newTypeface = Typeface.createFromAsset(getAssets(), "AguafinaScript-Regular.ttf");
CustomHint customHint = new CustomHint(newTypeface, "Enter some text", Typeface.BOLD_ITALIC, 60f);
// CustomHint customHint = new CustomHint(newTypeface, "Enter some text", Typeface.BOLD_ITALIC);
// CustomHint customHint = new CustomHint(newTypeface, "Enter some text", 60f);
// CustomHint customHint = new CustomHint("Enter some text", Typeface.BOLD_ITALIC, 60f);
// CustomHint customHint = new CustomHint("Enter some text", Typeface.BOLD_ITALIC);
// CustomHint customHint = new CustomHint("Enter some text", 60f);
customEditText.setHint(customHint);
相关问题
- 1. 不显示文本字体样式
- 2. 嵌入式字体样式 - 嵌入式字体风格VS CSS样式
- 3. 提示的背景颜色变化和字体样式primefaces提示文本的
- 4. Android Black Roboto字体样式
- 5. 字体样式@字体面不与本地字体工作
- 6. iText PDF字体和样式的文本提取
- 7. Tkinter字体样式
- 8. 已下载有不同字体样式的字体
- 9. 自定义字体和粗体样式的文本
- 10. 如何为文本视图设置不同的字体样式
- 11. sifr 3.0 - 字体样式不显示?
- 12. SVG动画文本字体样式
- 13. 为什么字体样式不能去除'斜体'样式?
- 14. 嵌入字体WordPress的样式表
- 15. CSS - 样式字体Awesome字体图标
- 16. 如何使用pdfbox提取文本内容的字体样式?
- 17. 设置jeditorpane的字体和样式
- 18. JTextComponent中的多种字体和样式
- 19. css font-face显示引用网站的不同字体样式?
- 20. 如何显示州际字体的不同重量/样式?
- 21. 以不同的字体样式收集用户输入
- 22. 不稳定的字体特殊样式
- 23. Android的 - 多种字体样式,组合成一个单一的字体(字体)
- 24. 加入字体样式到弯曲文本中的jquery
- 25. 更改字体样式
- 26. 更改字体样式
- 27. Xamarin Forms Android:TabbedPage字体样式
- 28. Windows Phone 7字体样式
- 29. ios7 UILabel字体样式
- 30. CSS平滑字体样式