EditText提示文字

时间:2021-11-01 22:54:01

EditText提示文字

如图,在没有输入文字前,会显示提醒文字。

引用的是文本文件(strings.xml)中的对应文字

activity_main.xml对应的红色代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="examples.ouc.com.myapplication2.MainActivity"
tools:showIn="@layout/activity_main"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etUser"
android:hint="@string/hint_etUser"
android:layout_below="@+id/textView"
android:layout_alignParentEnd="true" />
<EditText
android:id="@+id/etPassword"
android:hint="@string/hint_etPassword"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etUser"
android:layout_alignParentEnd="true" />
</RelativeLayout>

strings.xml中对应的代码为:

 <resources>
<string name="app_name">My Application2</string>
<string name="action_settings">Settings</string>
<string name="hint_etUser">User Name</string>
<string name="hint_etPassword">Password</string>
<string name="hint_btSubmit">Submit</string>
<string name="text_btClear">Clear</string>
<string name="hint_etPhone">Phone Number</string>
<string name="hint_etAge">Age</string>
<string name="msg_ClearAllFields">clear all the fields</string>
</resources>