Reputation: 51
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.
Upvotes: 5
Views: 17994
Reputation: 11497
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"
Upvotes: 5
Reputation: 1921
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");
Upvotes: 3