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" />
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:
You could set the text size to the smaller, desired value, then set a text listener to change the text size after some text is entered.
Using HTML is ok, but it is not flexible. For example, you cannot set the exact size. I will provide an alternative solution where you can set:
1) Create a custom
Hint
object:2) Create custom
MetricAffectingSpan
object:3) Use:
You can set it in resource file.
For example:
And your XML: