I just need an editText in which i can set Text and hint at the same time. e.g i want user to enter in editText string like user#1234 in this string user# should be text after that numbers will vary so that 1234 should be show as hint when user try to enter cursor will go after # and 1234 hint will gone when user type a character.
Please guide me how to do this.
Thanks
To label an editable TextView or EditText , use android:hint to display a descriptive text label within the item when it's empty.
Make EditText non editable in Android To use this just set android:inputType="none" and it will become non editable.
Actually, android:gravity="center_horizontal" creates the centering effect you're looking for. Similarly, you can use android:gravity="start" to put hint text at the beginning of the EditText view, and so on.
In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.
I managed to achieved this with bit of tricks and playing with margin
and padding
This is what I did
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="user#" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="1234"
android:paddingLeft="40dp"
android:textSize="14sp" />
</RelativeLayout>
Hope this will help you out
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