Issue
I want to make drawable and text center in my EditText. The text is centered but the drawable is not. I want something like this: https://i.stack.imgur.com/2PMem.jpg
Please help. This is what I have done so far
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="center_horizontal"
android:drawableLeft="@drawable/lol2"
/>
When the user types in something in the EditText, the drawable should move itself to the left if the text is lenghty.
Solution
You can do something like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@android:drawable/editbox_background"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Username"
android:background="@null"
android:gravity="center"
android:drawableLeft="@drawable/ic_launcher"
/>
</RelativeLayout>
Answered By - Nauman Afzaal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.