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);//设置提示内容
}复制代码