I am trying to put a value in EditText
but I can not.
The code I edit:
<EditText android:textColor="@color/white" android:id="@id/input_username"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20.0dip" android:hint="@string/input_username_hint"
android:ems="10" android:singleLine="true" android:maxLength="140"
android:layout_below="@id/input_room_name" android:layout_centerHorizontal="true" />
When I put android:text="user"
the genarated apk is not opening.
You can use EditText. setText(...) to set the current text of an EditText field. Save this answer.
Set the Text of Android 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. Following is the example to set the text of TextView control while declaring it in XML Layout file.
The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.
Do this:
editText.setText("Your default text");
But if you want to show that gray text that disappears when the user starts to type, you're looking for android:hint
.
On xml:
android:hint="Your default text"
On java:
editText.setHint("Your default text");
On kotlin:
editText.hint = "Your default text"
In your .xml file,
specify
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="user" />
or
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="user" />
If you want to do it in program
do this
EditText et = (EditText)findViewById(R.id.your_edittext_id);
et.setText("user");
or
et.setHint("user");
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