Android EditText Hint Size

前端 未结 12 1164
轮回少年
轮回少年 2020-11-28 06:21

How to reduce EditText Hint size?

12条回答
  •  一生所求
    2020-11-28 06:49

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

提交回复
热议问题