I have a EditText
input field. I have added a hint in it. Now i want to change the size of hint text, but when i do this, it also effects the size of the text. Kindly guide me how to change the size of hint and text separately, and give different fonts to both the hint and the text.
<EditText
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:textSize="12sp"
android:textColor="#ffffff"
android:fontFamily="sans-serif-light"
android:hint="MM/YY"
android:textColorHint="@color/white" />
fromHtml( "<small><small><small>" + getString(R. string. hint) + "</small></small></small>")); Also, you can set the size in the string resource file where is the string for the hint.
You only need to change the android:textSize attribute for the TextInputEditText for the hint size to change. Save this answer. Show activity on this post. The problem is that i whant to make edit text size biger and hint smaller.
You can set it in resource file.
For example:
<string name="hint"><font size="20">Hint!</font></string>
And your XML:
android:hint="@string/hint"
The hint and the text are exclusive, if one of them is visible, the other one is not.
Because of this, you could just change the attributes of your EditText
depending on if it's empty (the hint is visible) or not (the text is visible).
For example:
final EditText editText = (EditText) findViewById(R.id.yourEditText);
editText.addTextChangedListener(new TextWatcher() {
boolean hint;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length() == 0) {
// no text, hint is visible
hint = true;
editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
editText.setTypeface(Typeface.createFromAsset(getAssets(),
"hintFont.ttf")); // setting the font
} else if(hint) {
// no hint, text is visible
hint = false;
editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
editText.setTypeface(Typeface.createFromAsset(getAssets(),
"textFont.ttf")); // setting the font
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With