EditText tooltip text and text

I am trying to create an EditText with a tooltip like icon and text together. But the tooltip text goes to the center, but I want the tooltip text to be left justified, so that there should be only a tab space (space) between the tooltip icon and the tooltip text.

Here is what I tried:

<EditText android:id="@+id/emailAddressInput" android:layout_width="match_parent" android:layout_height="40dp" android:ems="10" android:layout_marginTop ="20dp" android:layout_marginLeft ="20dp" android:layout_marginRight ="20dp" android:background="@drawable/rounded_edge" android:drawableLeft="@drawable/email_box" android:hint="e-mail address" android:gravity="left|center_vertical" android:maxLength="100" android:inputType="textEmailAddress" /> 

Any idea how I can achieve the desired result?

+2
source share
3 answers

So, after a little debugging, I found out that the image size takes up so much space, I reduced the image to a smaller size, and it worked.

+2
source

ImageSpan is the best way to do this.

But you have to do it with Java code.

 ImageSpan imageHint = new ImageSpan(mContext, R.drawable.icon_hint); SpannableString spannableString = new SpannableString("_I'm the hint"); spannableString.setSpan(imageHint, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); mEditor.setHint(spannableString); 
+5
source

Add

android:gravity="top"

into your EditText.

0
source

Source: https://habr.com/ru/post/958944/


All Articles