可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

How to reduce EditText Hint size?

回答1:

You can do it by setting a size in the string recource.

For example:

Hint here!

then in your XML just write

android:hint="@string/edittext_hint"

This will resault in a smaller text for the hint but the original size for the input text.

Hopes this helps for future readers

回答2:

You can reduce the font size on the EditText - that will reduce the size of the hint as well. i.e. android:textSize="16sp"

回答3:

I also had to do this as my hint didn't fit in the EditText at the standard size. So I did this (in the xml set textSize to mHintTextSize):

MYEditText.addTextChangedListener(new TextWatcher(){

@Override

public void afterTextChanged(Editable arg0) {

// TODO Auto-generated method stub

}

@Override

public void beforeTextChanged(CharSequence arg0, int arg1,

int arg2, int arg3) {

// TODO Auto-generated method stub

}

@Override

public void onTextChanged(CharSequence arg0, int start, int before,

int count) {

if (arg0.length() == 0) {

// No entered text so will show hint

editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mHintTextSize);

} else {

editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mRealTextSize);

}

}

});

回答4:

You can set simple HTML attributes to the hint string itself.

See accepted answer here:

Android EditText hint

EDIT: just played with it myself, this worked for me:

view.setHint(Html.fromHtml("" +

getString(R.string.hint) + ""));

This is a list of tags accepted by fromHtml:

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

(though didn't work for me)

回答5:

If you want to do it programmatically,

SpannableString span = new SpannableString(strHint);

span.setSpan(new RelativeSizeSpan(0.5f), 0, strHint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

editText.setHint(span);

回答6:

it is easy to reduce the hint size of the edittext

editText.setHint(Html.fromHtml(

"" + "hinttext1" + "" +

"" + "hinttext2" + "" ));

回答7:

@marmor 's Approach is the best One. You can alter the number of --- tags to adjust size.

You can also define the text of Hint directly as I did

view.setHint(Html.fromHtml("" +

"This is Hint" + ""));

Hope this will help.

回答8:

@user2982553 's solution works great for me. You could also use AbsoluteSizeSpan, with which you can set the exact font size of the hint. Don't use tag, 'cause the size attribute is just ignored.

回答9:

I need to set a larger size for real text than hint.

public static class LargeSizeTextWatcher implements TextWatcher {

private final EditText mEditText;

private final int mOriginalSize;

private final int mLargeSize;

private int mLastLength;

TrackingNumberTextWatcher(EditText editText) {

mEditText = editText;

mOriginalSize = (int) editText.getTextSize();

mLargeSize = editText.getResources().getDimensionPixelSize(R.dimen.text_size_large);

mLastLength = editText.length();

if (mLastLength != 0) {

mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeSize);

}

}

@Override

public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override

public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override

public void afterTextChanged(Editable s) {

int length = s.length();

if (length == 0) {

mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mOriginalSize);

} else if (mLastLength == 0) {

mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeSize);

}

mLastLength = length;

}

}

回答10:

You can change not only a hint's size but also its font and style. I achieved to solve it using SpannableString and MetricAffectingSpan

1) Create a custom Hint object:

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) Create custom MetricAffectingSpan object:

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) Use:

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);

android edittext hint值,Android EditText Hint Size相关推荐

  1. android layout_margin的值,Android自定义ViewGroup( 支持layout_margin属性)

    3. 支持layout_margin属性 如果我们自定义的布局参数类继承自MarginLayoutParams,就自动支持了layout_margin属性了,我们需要做的就是直接在布局文件中使用lay ...

  2. android fragment返回值,android – PreferenceFragment :: onPreferenceTreeClick返回值 – 它做什么?...

    调用它的代码在 Preference#performClick(PreferenceScreen preferenceScreen)中,它执行以下操作: PreferenceManager prefe ...

  3. Android系列教程之七:EditText使用详解-包含很多教程上看不到的功能演示

    写道 标题有点大,说是详解,其实就是对EditText的一些常用功能的介绍,包括密码框,电话框,空白提示文字等等的讲解,尽量的介绍详细一点,也就是所谓的详解了..呵呵 广告一下我的应用"我团 ...

  4. android开发中EditText自动获取焦点时隐藏hint的代码

    只需让EditText设置以下的OnFocusChangeListener就可以了 private OnFocusChangeListener mOnFocusChangeListener = new ...

  5. android 提示文字,EditText 不能显示提示文字Hint

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 帮我看下为什么不显示提示?夜神模拟器.靠谱助手.真机(三星安卓4.0.4)都不显示提示 代码: tts_str=(EditText)contextP.fi ...

  6. 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析

    . 作者 :万境绝尘  转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...

  7. android edittext限制字节_android EditText输入限制

    zyz 发表于 2012-5-30 18:19:03 android EditText输入限制 android:digits="1234567890.+-*/%\n()" 限制输入 ...

  8. android中fragment如何保存edittext文本,如何在Android中使用DialogFragment进行文本输入?...

    我想获得一个值,用户输入到一个对话框,使用建议的DialogFragment类为它,对话框构造和运行良好,但我不能返回EditText参数的值父类,没有得到一个空值指针异常.如何在Android中使用 ...

  9. 如何阻止EditText专注于Android中的Activity启动

    我在Android中有一个Activity ,其中包含两个元素: EditText ListView 当我的Activity开始时, EditText立即具有输入焦点(光标闪烁). 我不希望任何控件在 ...

最新文章

  1. 计算机存储盘教程,计算机操作系统 --- 磁盘存储器
  2. C# 把特定数字移动到数字前面,其他顺序不变。
  3. 写一个参数返回二进制中1的个数
  4. mysql为什么占用_mysql 3306端口被占用怎么办?
  5. 托管型呼叫中心与自建型呼叫中心的区别
  6. 有感于中国的系统分析员考试
  7. c语言程序流程图怎么写,C语言课程设计————写下流程图! 谢谢
  8. UI app界面的尺寸规范
  9. 谈谈如何提升工作效率,需要从这4方面入手!
  10. eclipse 使用 git合并develop分支到master分支步骤
  11. 给表格加上横向、纵向滚动条并对滚动条进行美化
  12. MDP 与 贝尔曼方程
  13. python图像处理学习笔记
  14. JAVA学习【IDEA转中文】
  15. java 实现秒抢_Java实现抢红包算法,附完整代码(公平版和手速版)
  16. 古典问题(兔子生崽):有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?(输出前40个月即可)
  17. css怎么设置页面缩放最小宽度
  18. 支付宝手机网站支付实战踩坑
  19. ozip解密_ozip解包工具下载oppo刷机包ozip解包一加ops解包
  20. 蓝牙智能营养电子秤解决方案

热门文章

  1. 《MySQL必修课:存储引擎大揭秘!InnoDB和MyISAM究竟谁更强?》
  2. java.lang.IllegalStateException: Not on FX application thread
  3. 互联网快讯:五菱与B站跨界合作;猿辅导积极转型素质教育
  4. 获得UAA access token
  5. 知乎获赞超5W,这4款手机app是如何做到的?
  6. 跨时钟域(CDC)设计方法之多bit信号篇(一)
  7. 通过函数指针调用static
  8. 三维可视化数据管理系统详情分析
  9. 百度地图jsapi在手机站里实现中心标注不随地图移动的效果
  10. python培训 广州大学城