Hai, I have an Android Program with one text field. I need to display a message inside that textfield when it loads on an emulator. When the user clicks inside that textbox that message should dispappear. For Ex: Please enter name Can any one post some sample code over here...
Step 1: Create a new project in Android Studio and name it EditTextExample. Step 2: Now Open res -> layout -> xml (or) activity_main. xml and add following code. In this code we have added multiple edittext and a button with onclick functionality.
EditText is used for user input. TextView is used to display text and is not editable by the user. TextView can be updated programatically at any time.
How to include a Edittext in an Android App: First of all, create a new Android app, or take an existing app to edit it. In both the case, there must be an XML layout activity file and a Java class file linked to this activity. Open the Activity file and include a Edittext field in the layout (activity_main.
Just use or call setHint
on the object. Hint text to display when the text is empty.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18px"
android:gravity="left"
android:hint="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse egestas ullamcorper facilisis." />
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