Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hint and Text in editText at same time

Tags:

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

like image 411
Khizar Hayat Avatar asked Mar 22 '16 11:03

Khizar Hayat


People also ask

What is edit text hint?

To label an editable TextView or EditText , use android:hint to display a descriptive text label within the item when it's empty.

How do you make EditText not editable and clickable?

Make EditText non editable in Android To use this just set android:inputType="none" and it will become non editable.

How do you center text hint on android?

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.

Can you set text in EditText?

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.


1 Answers

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

like image 56
V-rund Puro-hit Avatar answered Oct 11 '22 05:10

V-rund Puro-hit