首页 > 代码库 > EditText提示文字

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中对应的代码为:

技术分享
 1 <resources> 2     <string name="app_name">My Application2</string> 3     <string name="action_settings">Settings</string> 4     <string name="hint_etUser">User Name</string> 5     <string name="hint_etPassword">Password</string> 6     <string name="hint_btSubmit">Submit</string> 7     <string name="text_btClear">Clear</string> 8     <string name="hint_etPhone">Phone Number</string> 9     <string name="hint_etAge">Age</string>10     <string name="msg_ClearAllFields">clear all the fields</string>11 </resources>
View Code

 

EditText提示文字