【问题标题】:Android EditText hintAndroid EditText 提示
【发布时间】:2011-03-05 11:18:54
【问题描述】:

您好,我正在使用 EditText,它的提示是“密码(至少 12 个字符)”两个文本的大小不同,即“密码”和“(至少 12 个字符)”我该如何设置?

【问题讨论】:

  • 你想在edittext上设置提示..?
  • 是的,但是提示句中包含大小不同的单词
  • 我不确定,但我认为这是不可能的。可能会改变提示的颜色..

标签: android


【解决方案1】:

我已经找到了一种通过设置来做到这一点的方法

editTextPassword.setHint(Html.fromHtml("<font size=\"16\">" + "Password     " + "</font>" + "<small>" + "(at least 12 charcters)" + "</small>" ));    

它对我有用。

【讨论】:

  • 很棒的答案...很棒
【解决方案2】:
editText.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) {           

    }

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

onCreate 中,您还需要根据您的要求更改文本大小。

【讨论】:

    【解决方案3】:

    或者,改变文本的大小会影响提示的大小...

    <EditText 
     ...
    android:textSize="14dp"/>
    

    【讨论】:

      猜你喜欢
      • 2013-04-14
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 2013-06-29
      • 2011-04-06
      相关资源
      最近更新 更多