当前位置: 代码迷 >> Android >> Android 说说EditText里头的属性
  详细解决方案

Android 说说EditText里头的属性

热度:30   发布时间:2016-05-01 17:16:00.0
Android 说说EditText里面的属性

android:layout_gravity="center_vertical"??

  1. ??
  2. 设置控件显示的位置:默认?top,这里居中显示,还有bottom??
  3. ??
  4. ??
  5. ??
  6. android:hint="请输入数字!"??
  7. ??
  8. 设置显示在空间上的提示信息??
  9. ??
  10. ??
  11. ??
  12. android:numeric="integer"??
  13. ??
  14. 设置只能输入整数,如果是小数则是:decimal??
  15. ??
  16. ??
  17. ??
  18. android:singleLine="true"??
  19. ??
  20. 设置单行输入,一旦设置为true,则文字不会自动换行。??
  21. ??
  22. ??
  23. ??
  24. android:password="true"??
  25. ??
  26. 设置只能输入密码??
  27. ??
  28. ??
  29. ??
  30. android:textColor?=?"#ff8c00"??
  31. ??
  32. 字体颜色??
  33. ??
  34. ??
  35. ??
  36. android:textStyle="bold"??
  37. ??
  38. 字体,bold,?italic,?bolditalic??
  39. ??
  40. ??
  41. ??
  42. android:textSize="20dip"??
  43. ??
  44. 大小??
  45. ??
  46. ??
  47. ??
  48. android:capitalize?=?"characters"??
  49. ??
  50. 以大写字母写??
  51. ??
  52. ??
  53. ??
  54. android:textAlign="center"??
  55. ??
  56. EditText没有这个属性,但TextView有,居中??
  57. ??
  58. ??
  59. ??
  60. ??
  61. ??
  62. android:textColorHighlight="#cccccc"??
  63. ??
  64. 被选中文字的底色,默认为蓝色??
  65. ??
  66. ??
  67. ??
  68. android:textColorHint="#ffff00"??
  69. ??
  70. 设置提示信息文字的颜色,默认为灰色??
  71. ??
  72. ??
  73. ??
  74. android:textScaleX="1.5"??
  75. ??
  76. 控制字与字之间的间距??
  77. ??
  78. ??
  79. ??
  80. android:typeface="monospace"??
  81. ??
  82. 字型,normal,?sans,?serif,?monospace??
  83. ??
  84. ??
  85. ??
  86. android:background="@null"??
  87. ??
  88. 空间背景,这里没有,指透明??
  89. ??
  90. ??
  91. ??
  92. android:layout_weight="1"??
  93. ??
  94. 权重,控制控件之间的地位,在控制控件显示的大小时蛮有用的。??
  95. ??
  96. ??
  97. ??
  98. android:textAppearance="?android:attr/textAppearanceLargeInverse"??
  99. ??
  100. EditText始终不弹出软件键盘??

1.EditText默认不弹出软件键盘

  方法一:
  在 AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为 adjustUnspecified|stateHidden
java代码:
复制到剪贴板??Java代码
  1. <?activity?android:name=".Main"??
  2. ??
  3. ??
  4. ??
  5. android:label="@string/app_name"??
  6. ??
  7. android:windowSoftInputMode="adjustUnspecified|stateHidden"??
  8. ??
  9. android:configChanges="orientation|keyboardHidden">??
  10. ??
  11. ??
  12. ??
  13. <?intent-filter>??
  14. ??
  15. <?action?android:name="android.intent.action.MAIN"?/>??
  16. ??
  17. <?category?android:name="android.intent.category.LAUNCHER"?/>??
  18. ??
  19. <?/intent-filter>??
  20. ??
  21. <?/activity>??

方法二:
  让 EditText失去焦点,使用EditText的clearFocus方法
  例如:EditText edit=(EditText)findViewById(R.id.edit);
  edit.clearFocus();

? ?? ? 方法三:
  强制隐藏Android输入法窗口

java代码:
复制到剪贴板??Java代码
  1. EditText?edit=(EditText)findViewById(R.id.edit);??
  2. ??
  3. ??
  4. ??
  5. InputMethodManager?imm?=?(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);??
  6. ??
  7. ??
  8. ??
  9. imm.hideSoftInputFromWindow(edit.getWindowToken(),0);??
  相关解决方案