现在的位置: 首页 > 综合 > 正文

android 带提示的输入框

2013年08月28日 ⁄ 综合 ⁄ 共 3269字 ⁄ 字号 评论关闭

 

在需要用户输入数据的时候,友好的界面是非常重要的,所以如果我们能在输入框给用户一些提示,将能很好的提高程序的易用性,android就给我们提供了这样一个属性,也就是android:hint。

另外这个程序的textview里面使用一下android中的shape属性,可以参见我前一篇转载的博客。

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <TableRow>  
  8. <TextView  
  9.     android:layout_width="fill_parent"  
  10.     android:layout_height="wrap_content"  
  11.     android:text="用户名:"  
  12.     android:textSize="10sp"  
  13.     android:background="@drawable/bg_border"  
  14.     />     
  15. <EditText   
  16.     android:layout_width="fill_parent"  
  17.     android:layout_height="wrap_content"  
  18.     android:hint="请填写登录帐号"  
  19.     android:selectAllOnFocus="true"  
  20.     />  
  21. </TableRow>  
  22. <TableRow>  
  23. <TextView  
  24.     android:layout_width="fill_parent"  
  25.     android:layout_height="wrap_content"  
  26.     android:text="密码:"  
  27.     android:textSize="10pt"   
  28.     android:background="@drawable/bg_border"  
  29.     />     
  30. <EditText  
  31.     android:layout_width="fill_parent"  
  32.     android:layout_height="wrap_content"  
  33.     android:password="true"  
  34.     />  
  35. </TableRow>  
  36. <TableRow>  
  37. <TextView  
  38.     android:layout_width="fill_parent"  
  39.     android:layout_height="wrap_content"  
  40.     android:text="电话号码:"  
  41.     android:textSize="10pt"   
  42.     android:background="@drawable/bg_border"  
  43.     />     
  44. <EditText  
  45.     android:layout_width="fill_parent"  
  46.     android:layout_height="wrap_content"  
  47.     android:hint="请填写您的电话号码"  
  48.     android:selectAllOnFocus="true"  
  49.     android:phoneNumber="true"  
  50.     />  
  51. </TableRow>  
  52. <Button   
  53.     android:layout_width="wrap_content"  
  54.     android:layout_height="wrap_content"  
  55.     android:text="注册"  
  56.     />  
  57. </TableLayout>  


 使用的shape文件

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">   
  3.     <solid android:color="#000000"/>  
  4.     <stroke android:width="2dip" android:color="#ff0000" />  
  5. </shape>  

抱歉!评论已关闭.