A text field allows the user to type text into your app. It can be either single line or multi-line. Touching a text field places the cursor and automatically displays the keyboard. In addition to typing, text fields allow for a variety of other activities, such as text selection (cut, copy, paste) and data look-up via auto-completion. You can add a text field to you layout with the EditText object. You should usually do so in your XML layout with a < EditText > element.javascript
文本區域給用戶輸入文字提供了方便,它能夠是單行的也能夠是多行的。觸摸一個文本區域獲取光標而且自動彈出鍵盤。除了能夠輸入文字,文本區域還能夠用來執行如文本選中(剪切,複製和粘貼)和經過自動補全實現的數據查詢等功能。你能夠經過在佈局中添加一個EditText對象來實現文本區域,固然也能夠在佈局文件中添加EditText Tag. html
這裏寫圖片描述
指定鍵盤類型
Text fields can have different input types, such as number, date, password, or email address. The type determines what kind of characters are allowed inside the field, and may prompt the virtual keyboard to optimize its layout for frequently used characters.java
You can specify the type of keyboard you want for your EditText object with the android:inputType attribute. For example, if you want the user to input an email address, you should use the textEmailAddress input type: 文本區域有不一樣的輸入類型,如數字,日期,密碼或者郵箱地址。輸入類型決定了文本區域內容許輸入的字符類型,同時也提示着虛擬鍵盤給用戶展現更加經常使用的字符集合。咱們能夠經過使用 android:inputType 屬性來明確咱們的輸入框想要的鍵盤類型。例如,若是你想要輸入郵箱地址,你可使用textEmailAddress輸入類型。android
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get a reference to the AutoCompleteTextView in the layout
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
// Get the string arrayString[] countries = getResources().getStringArray(R.array.countries_array);
// Create the adapter and set it to the AutoCompleteTextView
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
textView.setAdapter(adapter);//設置提示內容
}複製代碼