{"id":788,"date":"2015-06-12T15:02:18","date_gmt":"2015-06-12T07:02:18","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=788"},"modified":"2016-05-17T17:26:50","modified_gmt":"2016-05-17T09:26:50","slug":"android%e6%96%87%e6%9c%ac%e8%be%93%e5%85%a5%e6%8e%a7%e4%bb%b6edittext","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=788","title":{"rendered":"Android\u6587\u672c\u8f93\u5165\u63a7\u4ef6EditText"},"content":{"rendered":"<p>EditText\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u8bf4\u5b83\u662f\u7528\u6237\u548cAndroid\u5e94\u7528\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u7a97\u6237\uff0c\u8fc7\u5b83\u7528\u6237\u53ef\u4ee5\u628a\u6570\u636e\u4f20\u7ed9Android\u5e94\u7528\uff0c\u7136\u540e\u5f97\u5230\u6211\u4eec\u60f3\u8981\u7684\u6570\u636e\u3002<br \/>\nEditText\u662fTextView\u7684\u5b50\u7c7b\uff0c\u6240\u4ee5TextView\u7684\u65b9\u6cd5\u548c\u7279\u6027\u540c\u6837\u5b58\u5728\u4e8eEditText\u4e2d.<br \/>\n<!--more--><\/p>\n<p>\u5b66\u4e60\u5185\u5bb9\uff1a1.\u5e38\u7528\u5c5e\u6027<br \/>\n2.\u6587\u672c\u76d1\u542c TextChangedListener<br \/>\n3.\u9519\u8bef\u63d0\u793a. setError<br \/>\n4.\u81ea\u5b9a\u4e49\u6837\u5f0f<\/p>\n<p>\u4e00\uff1a\u957f\u5ea6\u548c\u7a7a\u767d\u63d0\u793a\u6587\u5b57,\u63d0\u793a\u6587\u5b57\u989c\u8272,\u662f\u5426\u53ef\u7f16\u8f91\u7b49<br \/>\nEditText\u6709\u4e00\u4e9b\u5c5e\u6027\u53ef\u4ee5\u8bbe\u7f6eEditText\u7684\u7279\u6027\uff0c\u6bd4\u5982\u6700\u5927\u957f\u5ea6\uff0c\u7a7a\u767d\u63d0\u793a\u6587\u5b57\u7b49\u3002<br \/>\n\u6709\u65f6\u5019\u6211\u4eec\u6709\u4e00\u4e9b\u7279\u6b8a\u7684\u9700\u8981\uff0c\u8981\u6c42\u53ea\u80fd\u5728EditText\u4e2d\u8f93\u5165\u7279\u5b9a\u4e2a\u6570\u7684\u5b57\u7b26\uff0c\u6bd4\u5982\u8eab\u4efd\u8bc1\u53f7\u3001\u624b\u673a\u53f7\u5417\u7b49\u3002\u8fd9\u65f6\u5019\u5c31\u53ef\u4ee5\u901a\u8fc7android:maxLength\u5c5e\u6027\u6765\u8bbe\u7f6e\u6700\u5927\u8f93\u5165\u5b57\u7b26\u4e2a\u6570\uff0c\u6bd4\u5982android:maxLength=\u201c4\u201d\u5c31\u8868\u793a\u6700\u591a\u80fd\u8f93\u51654\u4e2a\u5b57\u7b26\uff0c\u518d\u591a\u4e86\u5c31\u8f93\u5165\u4e0d\u8fdb\u53bb\u4e86\u3002<br \/>\n\u7a7a\u767d\u63d0\u793a\u6587\u5b57\u3002\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u8bf4\u660e\u4f60\u5b9a\u4e49\u7684\u8fd9\u4e2aEditText\u662f\u505a\u4ec0\u4e48\u7528\u7684\uff0c\u6bd4\u5982\u8ba9\u8f93\u5165\u201c\u7528\u6237\u540d\u201d\uff0c\u6216\u8005\u8f93\u5165\u201c\u7535\u8bdd\u53f7\u7801\u201d\u7b49\uff0c\u4f46\u662f\u4f60\u53c8\u4e0d\u60f3\u5728EditText\u524d\u9762\u52a0\u4e00\u4e2aTextView\u6765\u8bf4\u660e\u8fd9\u662f\u8f93\u5165\u201c\u7528\u6237\u540d\u201d\u7684\uff0c\u56e0\u4e3a\u8fd9\u4f1a\u4f7f\u7528\u4e00\u4e2aTextView\uff0c\u90a3\u4e48\u600e\u4e48\u529e\u5462\uff1fEditText\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86android:hint\u6765\u8bbe\u7f6e\u5f53EditText\u5185\u5bb9\u4e3a\u7a7a\u65f6\u663e\u793a\u7684\u6587\u672c\uff0c\u8fd9\u4e2a\u6587\u672c\u53ea\u5728EditText\u4e3a\u7a7a\u65f6\u663e\u793a\uff0c\u4f60\u8f93\u5165\u5b57\u7b26\u7684\u65f6\u5019\u5c31\u6d88\u5931\u4e86\uff0c\u4e0d\u5f71\u54cd\u4f60\u7684EditText\u7684\u6587\u672c\u3002\u3002\u4fee\u6539main.xml\u5982\u4e0b\uff1a<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:maxLength=&quot;40&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:hint=&quot;\u8bf7\u8f93\u5165\u7528\u6237\u540d&#8230;&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0\u00a0[\/java]<\/p>\n<p>\u4e0a\u9762\u5217\u51fa\u4e86\u7a7a\u767d\u65f6\u7684\u63d0\u793a\u6587\u5b57\uff0c\u6709\u7684\u4eba\u8bf4\u4e86\uff0c\u6211\u4e0d\u60f3\u8981\u8fd9\u4e2a\u7070\u8272\u7684\u63d0\u793a\u6587\u5b57\uff0c\u548c\u6211\u7684\u5e94\u7528\u6574\u4f53\u98ce\u683c\u4e0d\u534f\u8c03\uff0c\u90a3\u4e5f\u884c\u554a\uff0c\u6211\u4eec\u53ef\u4ee5\u6362\u989c\u8272\uff0c\u600e\u4e48\u6362\u5462\uff0c\u5c31\u662f\u901a\u8fc7android:textColorHint\u5c5e\u6027\u8bbe\u7f6e\u4f60\u60f3\u8981\u7684\u989c\u8272\u3002\u4fee\u6539main.xml\u5982\u4e0b:<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:maxLength=&quot;40&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:hint=&quot;\u8bf7\u8f93\u5165\u7528\u6237\u540d&#8230;&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:textColorHint=&quot;#238745&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0\u00a0[\/java]<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u6bd4\u8f83\u5b9e\u7528\u7684\u529f\u80fd\uff0c\u5c31\u662f\u8bbe\u7f6eEditText\u7684\u4e0d\u53ef\u7f16\u8f91\u3002\u8bbe\u7f6eandroid:enabled=&#8221;false&#8221;\u53ef\u4ee5\u5b9e\u73b0\u4e0d\u53ef\u7f16\u8f91\uff0c\u53ef\u4ee5\u83b7\u5f97\u7126\u70b9\u3002\u8fd9\u65f6\u5019\u6211\u4eec\u770b\u5230EditText\u548c\u4e00\u4e2aTextView\u5dee\u4e0d\u591a\uff1a<\/p>\n<p>\u56db\uff1a\u8f93\u5165\u7279\u6b8a\u683c\u5f0f\u7684\u5b57\u7b26<br \/>\n\u5728\u6211\u4eec\u5f00\u53d1\u7a0b\u5e8f\u7684\u65f6\u5019\u4e0d\u514d\u4f1a\u8f93\u5165\u4e00\u4e9b\u7279\u5c5e\u4e2a\u6570\u7684\u5b57\u7b26\uff0c\u6bd4\u5982\u5bc6\u7801\uff08\u8f93\u5165\u6846\u7684\u5b57\u7b26\u8981\u52a0\u5bc6\u663e\u793a\uff09\uff0c\u7535\u8bdd\u53f7\u7801\uff08\u6bd4\u5982\u6570\u5b57\u548c-\uff09,\u6570\u5b57\u7b49\uff0c\u8fd9\u4e9b\u90fd\u7b97\u662f\u4e00\u4e9b\u7279\u5c5e\u683c\u5f0f\u7684\u5b57\u7b26\uff0c\u5f3a\u5927\u7684EditText\u540c\u6837\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u8f93\u5165\u8fd9\u4e9b\u7279\u5c5e\u683c\u5f0f\u5b57\u7b26\u7684\u8bbe\u7f6e\u3002<br \/>\n\u5bc6\u7801\u6587\u672c\u6846\u3002\u5bc6\u7801\u8f93\u5165\u4e5f\u662fAndroid\u5e94\u7528\u5e38\u7528\u7684\u529f\u80fd\uff0c\u901a\u8fc7\u914d\u7f6eEditText\u7684android:password=&#8221;true&#8221;\u5c31\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u5bc6\u7801\u8f93\u5165\u529f\u80fd\uff0c\u4fee\u6539main.xml\u5982\u4e0b\uff1a<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:password=&quot;true&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0[\/java]<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u8f93\u5165\u7684\u5b57\u7b26\u5df2\u7ecf\u88ab\u201c.\u201d\u8fd9\u6837\u7684\u63a9\u7801\u6240\u4ee3\u66ff\u3002<br \/>\n\u624b\u673a\u4e2d\u53d1\u77ed\u4fe1\u6253\u7535\u8bdd\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\uff0c\u6240\u4ee5\u7528\u4e8e\u4e13\u95e8\u8f93\u5165\u7535\u8bdd\u53f7\u7801\u7684\u6587\u672c\u6846\u4e5f\u662f\u5927\u6709\u7528\u9014\uff0c\u6709\u4e86\u4ed6\u6211\u4eec\u5bf9\u662f\u5426\u662f\u7535\u8bdd\u53f7\u7801\u7684\u6821\u9a8c\u5c31\u5bb9\u6613\u7684\u591a\u4e86(\u56e0\u4e3a\u5b57\u7b26\u662f\u6b63\u786e\u7684\uff0c\u53ea\u8981\u6821\u9a8c\u683c\u5f0f ).\u901a\u8fc7\u8bbe\u7f6eandroid:phoneNumber=&#8221;true&#8221;\u5c31\u53ef\u4ee5\u628aEditText\u53d8\u6210\u53ea\u63a5\u53d7\u7535\u8bdd\u53f7\u7801\u8f93\u5165\u7684\u6587\u672c\u6846\uff0c\u8fde\u8f6f\u952e\u76d8\u90fd\u5df2\u7ecf\u53d8\u6210\u62e8\u53f7\u4e13\u7528\u8f6f\u952e\u76d8\u4e86\uff0c\u6240\u4ee5\u4e0d\u7528\u518d\u62c5\u5fc3\u8f93\u5165\u5176\u4ed6\u5b57\u7b26\u4e86\u3002\u4fee\u6539main.xml\u5982\u4e0b\uff1a<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:phoneNumber=&quot;true&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0\u00a0[\/java]<\/p>\n<p>\u6ce8\u610f\u770b\u8f6f\u952e\u76d8\uff0c\u5df2\u7ecf\u53d8\u6210\u62e8\u53f7\u4e13\u7528\u7684\u5566.<br \/>\n\u6709\u65f6\u5019\u6211\u4eec\u53ea\u60f3\u8f93\u5165\u6570\u5b57\uff0c\u4e0d\u60f3\u8f93\u5165\u5b57\u6bcd\uff0cEditText\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86android:numeric\u6765\u63a7\u5236\u8f93\u5165\u7684\u6570\u5b57\u7c7b\u578b\uff0c\u4e00\u5171\u6709\u4e09\u79cd\u5206\u522b\u4e3ainteger\uff08\u6b63\u6574\u6570\uff09\u3001signed\uff08\u5e26\u7b26\u53f7\u6574\u6570\uff09\u548cdecimal(\u6d6e\u70b9\u6570)\u3002\u8fd9\u91cc\u4ee5signed\u7c7b\u578b\u7684\u4e3a\u4f8b\uff0c\u4fee\u6539main.xml\u5982\u4e0b\uff1a<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:numeric=&quot;signed&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0\u00a0[\/java]<\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u7684\u8f6f\u952e\u76d8\u53d8\u6210\u201c\u6570\u5b57\u952e\u76d8\u201d\u7684\u53d8\u5316.<\/p>\n<p>\u4e94\uff1a\u4e3a\u6587\u672c\u6307\u5b9a\u7279\u5b9a\u7684\u8f6f\u952e\u76d8\u7c7b\u578b<br \/>\n\u524d\u9762\u6211\u4eec\u901a\u8fc7\u6307\u5b9a\u4e3a\u7535\u8bdd\u53f7\u7801\u7279\u5b9a\u683c\u5f0f\uff0c\u7136\u540e\u952e\u76d8\u7c7b\u578b\u53d8\u6210\u4e86\u62e8\u53f7\u4e13\u7528\u7684\u952e\u76d8\uff0c\u8fd9\u4e2a\u662f\u81ea\u52a8\u53d8\u7684\uff0c\u5176\u5b9e\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a \u8fc7android:inputType\u6765\u8bbe\u7f6e\u6587\u672c\u7684\u7c7b\u578b\uff0c\u8ba9\u8f93\u5165\u6cd5\u9009\u62e9\u5408\u9002\u7684\u8f6f\u952e\u76d8\u7684\u3002\u3002android:inputType\u6709\u5f88\u591a\u7c7b\u578b\uff0c\u8fd9\u91cc\u4f7f\u7528date\u7c7b\u578b\u6765\u6f14\u793a,\u4fee\u6539main.xml\u5982\u4e0b\uff1a<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:inputType=&quot;date&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0\u00a0[\/java]<\/p>\n<p>&nbsp;<\/p>\n<p>\u516d\uff1aEnter\u952e\u56fe\u6807\u7684\u8bbe\u7f6e<br \/>\n\u8f6f\u952e\u76d8\u7684Enter\u952e\u9ed8\u8ba4\u663e\u793a\u7684\u662f\u201c\u5b8c\u6210\u201d\u6587\u672c\uff0c\u6211\u4eec\u77e5\u9053\u6309Enter\u5efa\u8868\u793a\u524d\u7f6e\u5de5\u4f5c\u5df2\u7ecf\u51c6\u5907\u5b8c\u6bd5\u4e86\uff0c\u8981\u53bb\u4ec0\u4e48\u4ec0\u4e48\u5566\u3002\u6bd4\u5982\uff0c\u5728\u4e00\u4e2a\u641c\u7d22\u4e2d\uff0c\u6211\u4eec\u8f93\u5165\u8981\u641c\u7d22\u7684\u6587\u672c\uff0c\u7136\u540e\u6309Enter\u8868\u793a\u8981\u53bb\u641c\u7d22\u4e86\uff0c\u4f46\u662f\u9ed8\u8ba4\u7684Enter\u952e\u663e\u793a\u7684\u662f\u201c\u5b8c\u6210\u201d\u6587\u672c\uff0c\u770b\u7740\u4e0d\u592a\u5408\u9002\uff0c\u4e0d\u7b26\u5408\u641c\u7d22\u7684\u8bed\u4e49\uff0c\u5982\u679c\u80fd\u663e\u793a\u201c\u641c\u7d22\u201d\u4e24\u4e2a\u5b57\u6216\u8005\u663e\u793a\u4e00\u4e2a\u8868\u793a\u641c\u7d22\u7684\u56fe\u6807\u591a\u597d\u3002\u4e8b\u5b9e\u8bc1\u660e\u6211\u4eec\u7684\u60f3\u6cd5\u662f\u5408\u7406\u7684\uff0cAndroid\u4e5f\u4e3a\u6211\u4eec\u63d0\u4f9b\u7684\u8fd9\u6837\u7684\u529f\u80fd\u3002\u901a\u8fc7\u8bbe\u7f6eandroid:imeOptions\u6765\u6539\u53d8\u9ed8\u8ba4\u7684\u201c\u5b8c\u6210\u201d\u6587\u672c\u3002\u8fd9\u91cc\u4e3e\u51e0\u4e2a\u5e38\u7528\u7684\u5e38\u91cf\u503c\uff1a<br \/>\nactionUnspecified \u672a\u6307\u5b9a\uff0c\u5bf9\u5e94\u5e38\u91cfEditorInfo.IME_ACTION_UNSPECIFIED.\u6548\u679c\uff1a<br \/>\nactionNone \u6ca1\u6709\u52a8\u4f5c,\u5bf9\u5e94\u5e38\u91cfEditorInfo.IME_ACTION_NONE \u6548\u679c\uff1a<br \/>\nactionGo \u53bb\u5f80\uff0c\u5bf9\u5e94\u5e38\u91cfEditorInfo.IME_ACTION_GO \u6548\u679c\uff1a<br \/>\nactionSearch \u641c\u7d22\uff0c\u5bf9\u5e94\u5e38\u91cfEditorInfo.IME_ACTION_SEARCH \u6548\u679c\uff1a<br \/>\nactionSend \u53d1\u9001\uff0c\u5bf9\u5e94\u5e38\u91cfEditorInfo.IME_ACTION_SEND \u6548\u679c\uff1a<br \/>\nactionNext \u4e0b\u4e00\u4e2a\uff0c\u5bf9\u5e94\u5e38\u91cfEditorInfo.IME_ACTION_NEXT \u6548\u679c\uff1a<br \/>\nactionDone \u5b8c\u6210\uff0c\u5bf9\u5e94\u5e38\u91cfEditorInfo.IME_ACTION_DONE \u6548\u679c\uff1a<br \/>\n\u4e0b\u9762\u5df2\u641c\u7d22\u4e3a\u4f8b\uff0c\u6f14\u793a\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u4fee\u6539main.xml\u5982\u4e0b\uff1a<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:imeOptions=&quot;actionSearch&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0\u00a0[\/java]<\/p>\n<p>\u4fee\u6539HelloEditText\u5982\u4e0b\uff1a<br \/>\nJava\u4ee3\u7801<\/p>\n<p>[java]package com.flysnow; \u00a0<br \/>\n\u00a0\u00a0<br \/>\nimport android.app.Activity; \u00a0<br \/>\nimport android.os.Bundle; \u00a0<br \/>\nimport android.view.KeyEvent; \u00a0<br \/>\nimport android.widget.EditText; \u00a0<br \/>\nimport android.widget.TextView; \u00a0<br \/>\nimport android.widget.Toast; \u00a0<br \/>\nimport android.widget.TextView.OnEditorActionListener; \u00a0<br \/>\n\u00a0\u00a0<br \/>\npublic class HelloEditText extends Activity { \u00a0<br \/>\n\u00a0\u00a0\u00a0 \/** Called when the activity is first created. *\/ \u00a0<br \/>\n\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0 public void onCreate(Bundle savedInstanceState) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 super.onCreate(savedInstanceState); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setContentView(R.layout.main); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 EditText editText=(EditText)findViewById(R.id.edit_text); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 editText.setOnEditorActionListener(new OnEditorActionListener() { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Toast.makeText(HelloEditText.this, String.valueOf(actionId), Toast.LENGTH_SHORT).show(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return false; \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }); \u00a0<br \/>\n\u00a0\u00a0\u00a0 } \u00a0<br \/>\n} \u00a0[\/java]<\/p>\n<p>\u8fd0\u884c\u7a0b\u5e8f\uff0c\u70b9\u51fb\u56de\u8f66\uff08\u4e5f\u5c31\u662f\u641c\u7d22\u56fe\u6807\u8f6f\u952e\u76d8\u6309\u94ae\uff09\u4f1a\u663e\u793a\u8be5actionId.\u6211\u4eec\u4e0a\u9762\u7684\u6bcf\u4e00\u4e2a\u8bbe\u7f6e\u90fd\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u5e38\u91cf\uff0c\u8fd9\u91cc\u7684actionId\u5c31\u662f\u90a3\u4e2a\u5e38\u91cf\u503c\u3002<\/p>\n<p>\u4e03\uff1aEditText\u7684\u53d6\u503c\u3001\u5168\u9009\u3001\u90e8\u5206\u9009\u62e9\u3001\u83b7\u53d6\u9009\u4e2d\u6587\u672c<br \/>\n\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u6f14\u793aEditText\u7684\u53d6\u503c\u3001\u5168\u9009\u3001\u90e8\u5206\u9009\u62e9\u548c\u83b7\u53d6\u9009\u4e2d\u6587\u672c.main.xml\u4fee\u6539\u5982\u4e0b\uff1a<br \/>\nXml\u4ee3\u7801<\/p>\n<p>[java]&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\u00a0\u00a0<br \/>\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:orientation=&quot;vertical&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;fill_parent&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 &gt;\u00a0\u00a0<br \/>\n&lt;EditText \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/edit_text&quot; \u00a0\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;fill_parent&quot; \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:imeOptions=&quot;actionSearch&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;Button \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/btn_get_value&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:text=&quot;\u53d6\u503c&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;Button \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/btn_all&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:text=&quot;\u5168\u9009&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;Button \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/btn_select&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:text=&quot;\u4ece\u7b2c2\u4e2a\u5b57\u7b26\u5f00\u59cb\u9009\u62e9&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;Button \u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0 android:id=&quot;@+id\/btn_get_select&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:text=&quot;\u83b7\u53d6\u9009\u4e2d\u6587\u672c&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_width=&quot;wrap_content&quot; \u00a0<br \/>\n\u00a0\u00a0\u00a0 android:layout_height=&quot;wrap_content&quot;\/&gt;\u00a0\u00a0<br \/>\n&lt;\/LinearLayout&gt;\u00a0\u00a0[\/java]<\/p>\n<p>HelloEditText\u4fee\u6539\u5982\u4e0b\uff1a<br \/>\nJava\u4ee3\u7801<\/p>\n<p>[java]import android.app.Activity; \u00a0<br \/>\nimport android.os.Bundle; \u00a0<br \/>\nimport android.text.Editable; \u00a0<br \/>\nimport android.text.Selection; \u00a0<br \/>\nimport android.view.KeyEvent; \u00a0<br \/>\nimport android.view.View; \u00a0<br \/>\nimport android.view.View.OnClickListener; \u00a0<br \/>\nimport android.widget.Button; \u00a0<br \/>\nimport android.widget.EditText; \u00a0<br \/>\nimport android.widget.TextView; \u00a0<br \/>\nimport android.widget.Toast; \u00a0<br \/>\nimport android.widget.TextView.OnEditorActionListener; \u00a0<br \/>\n\/**<br \/>\n\u00a0* EditText\u6f14\u793a\u00a0<br \/>\n\u00a0* @since 2010-11-29<br \/>\n\u00a0*\/ \u00a0<br \/>\npublic class HelloEditText extends Activity { \u00a0<br \/>\n\u00a0\u00a0\u00a0 \/** Called when the activity is first created. *\/ \u00a0<br \/>\n\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0 public void onCreate(Bundle savedInstanceState) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 super.onCreate(savedInstanceState); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 setContentView(R.layout.main); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 final EditText editText=(EditText)findViewById(R.id.edit_text); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u76d1\u542c\u56de\u8f66\u952e\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 editText.setOnEditorActionListener(new OnEditorActionListener() { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Toast.makeText(HelloEditText.this, String.valueOf(actionId), Toast.LENGTH_SHORT).show(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return false; \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u83b7\u53d6EditText\u6587\u672c\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Button getValue=(Button)findViewById(R.id.btn_get_value); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 getValue.setOnClickListener(new OnClickListener() { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void onClick(View v) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Toast.makeText(HelloEditText.this, editText.getText().toString(), Toast.LENGTH_SHORT).show(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u8ba9EditText\u5168\u9009\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Button all=(Button)findViewById(R.id.btn_all); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 all.setOnClickListener(new OnClickListener() { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void onClick(View v) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 editText.selectAll(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u4ece\u7b2c2\u4e2a\u5b57\u7b26\u5f00\u59cb\u9009\u62e9EditText\u6587\u672c\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Button select=(Button)findViewById(R.id.btn_select); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 select.setOnClickListener(new OnClickListener() { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void onClick(View v) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Editable editable=editText.getText(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Selection.setSelection(editable, 1,editable.length()); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u83b7\u53d6\u9009\u4e2d\u7684\u6587\u672c\u00a0\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Button getSelect=(Button)findViewById(R.id.btn_get_select); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 getSelect.setOnClickListener(new OnClickListener() { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void onClick(View v) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int start=editText.getSelectionStart(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int end=editText.getSelectionEnd(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CharSequence selectText=editText.getText().subSequence(start, end); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Toast.makeText(HelloEditText.this, selectText, Toast.LENGTH_SHORT).show(); \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }); \u00a0<br \/>\n\u00a0\u00a0\u00a0 } \u00a0<br \/>\n\u00a0\u00a0\u00a0 \/**<br \/>\n\u00a0\u00a0\u00a0\u00a0 * \u4ea4\u6362\u4e24\u4e2a\u7d22\u5f15\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0 * @param start \u5f00\u59cb\u7d22\u5f15\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0 * @param end \u7ed3\u675f\u7d22\u5f15\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0 *\/ \u00a0<br \/>\n\u00a0\u00a0\u00a0 protected void switchIndex(int start, int end) { \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int temp=start; \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 start=end; \u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 end=temp; \u00a0<br \/>\n\u00a0\u00a0\u00a0 } \u00a0<br \/>\n} \u00a0[\/java]<\/p>\n<h3>\u4f7f\u7528TextInputLayout\u5b9e\u73b0\u663e\u793a\u5728EditText\u4e0a\u65b9\u7684\u6d6e\u52a8\u6807\u7b7e<\/h3>\n<p><strong>\u8981\u4f7f\u7528TextInputLayout\u63a7\u4ef6\uff0c\u4f60\u9700\u8981\u5bfc\u5165\u4e24\u4e2aLibrary\u3002<\/strong><br \/>\n\u7b2c\u4e00\u4e2a\u662fappcompat-v7,\u5b83\u786e\u4fddmaterial style\u53ef\u4ee5\u5411\u540e\u517c\u5bb9\u3002\u7b2c\u4e8c\u4e2a\u662fDesign Support Library\u3002\u5728\u4f60\u7684build.gradle\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u5982\u4e0b\u4f9d\u8d56\uff1a<br \/>\n[java]<br \/>\ndependencies {<br \/>\n    compile fileTree(dir: &#8216;libs&#8217;, include: [&#8216;*.jar&#8217;])<\/p>\n<p>    compile &#8216;com.android.support:appcompat-v7:23.4.0&#8217;<br \/>\n    compile &#8216;com.android.support:design:23.4.0&#8217;<br \/>\n}<br \/>\n[\/java]<\/p>\n<p><strong>\u5e03\u5c40\u6587\u4ef6\u4e2d\u4f7f\u7528\u53c2\u8003\u5982\u4e0b:<\/strong><br \/>\n[java]<br \/>\n&lt;LinearLayout<br \/>\n        android:layout_width=&quot;match_parent&quot;<br \/>\n        android:layout_height=&quot;wrap_content&quot;<br \/>\n        android:orientation=&quot;vertical&quot;&gt;<\/p>\n<p>        &lt;EditText<br \/>\n            android:id=&quot;@+id\/username&quot;<br \/>\n            android:layout_width=&quot;match_parent&quot;<br \/>\n            android:layout_height=&quot;wrap_content&quot;<br \/>\n            android:hint=&quot;\u8f93\u5165\u7528\u6237\u540d:&quot;<br \/>\n            android:inputType=&quot;textEmailAddress&quot; \/&gt;<\/p>\n<p>        &lt;android.support.design.widget.TextInputLayout<br \/>\n            android:id=&quot;@+id\/passwordWrapper&quot;<br \/>\n            android:layout_width=&quot;match_parent&quot;<br \/>\n            android:layout_height=&quot;wrap_content&quot;<br \/>\n            android:layout_marginTop=&quot;4dp&quot;&gt;<\/p>\n<p>            &lt;EditText<br \/>\n                android:id=&quot;@+id\/password&quot;<br \/>\n                android:layout_width=&quot;match_parent&quot;<br \/>\n                android:layout_height=&quot;wrap_content&quot;<br \/>\n                android:hint=&quot;\u8f93\u5165\u5bc6\u7801:&quot;<br \/>\n                android:inputType=&quot;textPassword&quot; \/&gt;<br \/>\n        &lt;\/android.support.design.widget.TextInputLayout&gt;<\/p>\n<p>        &lt;Button<br \/>\n            android:id=&quot;@+id\/login_demo_btn&quot;<br \/>\n            android:layout_width=&quot;match_parent&quot;<br \/>\n            android:layout_height=&quot;wrap_content&quot;<br \/>\n            android:layout_marginTop=&quot;4dp&quot;<br \/>\n            android:text=&quot;Login&quot; \/&gt;<br \/>\n    &lt;\/LinearLayout&gt;<br \/>\n[\/java]<\/p>\n<p><strong>\u83b7\u53d6\u8f93\u5165\u6846EditText\u5185\u5bb9\u53ef\u4ee5\u76f4\u63a5\u7528TextInputLayout\u5b9e\u4f8b\u83b7\u53d6\u5982\u4e0b:<\/strong><br \/>\n[java]<br \/>\nfinal TextInputLayout passwordWrapper = (TextInputLayout) findViewById(R.id.passwordWrapper);<br \/>\nString password = passwordWrapper.getEditText().getText().toString();<br \/>\n[\/java]<\/p>\n<p><strong>\u663e\u793a\u9519\u8bef\u4fe1\u606f\uff1a<\/strong><br \/>\n[java] passwordWrapper.setError(&quot;Not a valid password!&quot;);[\/java]<\/p>\n<p>\u53c2\u8003:http:\/\/www.jcodecraeer.com\/a\/basictutorial\/2015\/0821\/3338.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>EditText\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u8bf4\u5b83\u662f\u7528\u6237\u548cAndroid\u5e94\u7528\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u7a97\u6237\uff0c\u8fc7\u5b83\u7528\u6237\u53ef\u4ee5\u628a\u6570\u636e\u4f20 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/788"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=788"}],"version-history":[{"count":4,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/788\/revisions"}],"predecessor-version":[{"id":1587,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/788\/revisions\/1587"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}