Android - How put a backgroud text in a EditText? [duplicate] - android

This question already has answers here:
Android EditText background text
(2 answers)
Closed 6 years ago.
I have putted a EditText in a XML.
I want to use this EditText to the user insert his name.
I want that appears in this EditText the text "Insert the Name", but when the user click on it, the text "Insert the Name" disappear, so the user don't need to delete the phrase "Insert the Name".
I want the same "Event name" effect in this image:
What is needed to do in the EditText to get this effect?
Thanks!

Add hint in your Editext in your xml File
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Insert Name"/>

This will be helpful:
How to clear the selection in an EditText?
do it programatically by using:
myEditText.clearFocus();
which fills it up with actual text
or xml:
android:hint="text here"
which is unselectable greyed out 'hint' text you want

Related

how can i customize an edittext? [duplicate]

This question already has answers here:
Android EditText with different floating label and placeholder
(8 answers)
Closed 2 years ago.
var tel_text = "Enter your phone number"
Consider that the edittext is tel_text with a large font. When the user starts writing this article in edittext, I want it to be animated from bottom to top. How can I customize Edittext the easiest?
It looks like you want to add a hint to it which animates to the top when user begins to type. Wrap it inside TextInputLayout
<android.support.design.widget.TextInputLayout
android:id="#+id/edt_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your phone number">
<EditText
android:id="#+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>

Hint or Text value is not getting removed from edittext when user is typing in edittext

I am having a edittext in my layout i have tried putting hint or text in my edittext.
When i touch or click edittext for first time the mobile keypad popups to type text, which is expected but the text or hint inside edittext is not getting removed. i have to tap 2 times the edittext then first time the mobile keyboard popups and second tap removes the text.
i want on first tap itself the text should get removed from edittext.
for example : Suppose if EditText is having initial text as User Name, now when user click on edittext first time the User Name should get disappear so the user can type his name there.
below is my edittext code.
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginTop="30dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="start|top"
android:hint="Enter Name..."
android:textColor="#8c8c8c"
android:inputType="textMultiLine" />
Please help on above i have tried onClickListener also so that when we tap edittext it will make text empty but that also not working. i have to tap 2 times to remove text. i want the text should get disappear on first touch.
Please check below points -
Check if you have set any text to EditText dynamically? If yes, you can remove it and set the text as hint. As you said, if EditText is having initial text as User Name... if you want to show text as hint or you need it to show only for the first time. Then, you set the required text User Name as hint NOT AS TEXT to editText.
You can use editText.setHint("UserName") to set hint dynamically or android:hint="UserName" to set hint in xml.
If this is not the case, then you need to post the code snippets to find the exact error.

Password edittext hint text alignment on right side [duplicate]

This question already has answers here:
Android RTL password fields?
(6 answers)
Closed 6 years ago.
I'm facing an issue that when I define an EditText as password type and view my screen in Arabic language the password field hint text is showing on the left side instead of right side [that is expected].
Above is the result I get. I need password hint text to be starting from the right side that's where Arabic writings start. I've also tried adding text gravity to it but no luck.
Please refer to this post :
Android RTL password fields?
For API 17+ you can use
android:textAlignment="viewStart"
Try this:
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="كلمة المرور"
android:textColorHint="#FFFFFF"
android:gravity="right"
android:inputType="textPassword"
android:background="#null"
android:textColor="#FFFFFF"
android:textSize="20dp"/>

Android EditText not Multi Line [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
restrict edittext to single line
I have 2 edit texts. My problem is, when I press the enter button in the keyboard, it creates another set of line. Or it creates like a next line in my edit text. I want to remove it and I want it to be in single line. Even if I enter the enter key in the keyboard, still it won't create a next line.
How do you do it?
Try this in your EditText xml
android:singleLine="true"
<EditText
android:id="#+id/edittextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:singleLine="true"/>
Try this with your edit text in layout

How to replace text in a textfield when user enters any character [duplicate]

This question already has answers here:
TextView to display hint before text entered
(2 answers)
Closed 8 years ago.
In my android app I have a text field that says "how much would you like to take".
I want the text to be erased automatically and replaced by what the user inputs when they type in that textfield.
Example: if the user enters one character it automatically deletes "how much would you like to take" from the text field and replaces it with the one character that's been entered.
In your xml file use
android:hint="how much would you like to take"
in your TextView definition
(Well, it should be something like "#string/how_much" and that how_much string in strings.xml, but honestly...)
Its called android:hint property of a EditText you can set it into your xml file.
Something like that.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="how much would you like to take" />
Try this in your xml
Use this in below code android:hint="how much would you like to take"
<EditText
android:id="#+id/edtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtName"
android:layout_marginRight="5dip"
android:hint="how much would you like to take"
android:inputType="textCapSentences"
/>
Hope it helps

Categories

Resources