歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 帶提示的輸入框

Android 帶提示的輸入框

日期:2017/3/1 10:41:29   编辑:Linux編程

在需要用戶輸入數據的時候,友好的界面是非常重要的,所以如果我們能在輸入框給用戶一些提示,將能很好的提高程序的易用性,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>
  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>
Copyright © Linux教程網 All Rights Reserved