Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText hint

Tags:

android

hi am using EditText and it's hint is ' Password(at least 12 char) ' both the text are in different size ie 'Password' and '(at least 12 char)' how can i set this ?

like image 257
Bytecode Avatar asked Dec 08 '25 01:12

Bytecode


2 Answers

I have found a way to do this by setting

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

and it work for me.

like image 138
Bytecode Avatar answered Dec 10 '25 15:12

Bytecode


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

And in onCreate you also need to change text size according to your requirement.

like image 33
Narendra Avatar answered Dec 10 '25 14:12

Narendra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!