Method One:
After the text in the EditText is set to size, the hint text is too long to display in the EditText, so ask for an option to set the hint text size individually.
TextView Source code (EditText inherits from TextView), as follows:
Java
PublicFinalvoidSethint(Charsequence hint){Mhint= Textutils.Stringorspannedstring(Hint);If(Mlayout! = NULL){Checkforrelayout();}If(MText.Length()==0){Invalidate();}Invalidate Display list If hint is currently usedIf(Meditor! = NULL&& MText.length () == 0 && mHint != null) {meditor. Invalidatetextdisplaylist ( ) ; }}
At the beginning of the method is the conversion of the hint text. Since hint is a charsequence type, it is possible to add some custom properties, and we'll look at Textutils.stringorspannedstring this method:
PublicStatic charsequenceStringorspannedstring(Charsequence source){If(Source= = NULL)return null;If(SourceinstanceofSpannedstring)return source;if (source instanceof spanned) return new Span class= "Prism-token prism-class-name" >spannedstring (Sourcereturn source. Tostring () ; } /span>
As long as the incoming hint is a spannedstring or spanned type, can you keep the custom properties of the text? The answer is YES! Directly on the code:
EditText EditText=(EditText) Rootview.Findviewbyid(R. ID. ET);Create a new text object that can add properties spannablestring SS=NewSpannablestring("Drinking is going to take a pound!");Create a new Property object, set the size of the text Absolutesizespan=NewAbsolutesizespan(8,True);Attach property to Text SS.Setspan(The,0Ss.Length () ) ; //set Hintedittext.sethint (new spannedstring (Ss) ) ; //Be sure to convert, otherwise the property disappears
< Span class= "Prism-token prism-operator" > Note The final step, be sure to convert, the type is not converted to a string object, so the custom amount property will be lost.
Method Two:
<string name=
"Edittext_hint"
><font size=
"all"
>HINT&NBSP;HERE!</FONT></STRING>
android:hint=
"@string/edittext_hint"
Method Three:
SpannableString span = new SpannableString(strHint);span.setSpan(new RelativeSizeSpan(0.5f), 0, strHint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);editText.setHint(span);
&NBSP;
Customize the size of hint text in EditText in Android