📅  最后修改于: 2021-01-05 04:55:32             🧑  作者: Mango
输入控件是应用程序用户界面中的交互式组件。 Android提供了可在UI中使用的多种控件,例如按钮,文本字段,搜索栏,复选框,缩放按钮,切换按钮等等。
View是一个对象,它在屏幕上绘制一些用户可以与之交互的对象,而ViewGroup是一个对象,该对象包含其他View(和ViewGroup)对象,以便定义用户界面的布局。
您可以在XML文件中定义布局,该XML文件提供类似于HTML的易于阅读的结构。例如,带有文本视图和按钮的简单垂直布局如下所示:
Android提供了许多UI控件,可让您为应用构建图形用户界面。
Sr.No. | UI Control & Description |
---|---|
1 |
TextView
This control is used to display text to the user. |
2 |
EditText
EditText is a predefined subclass of TextView that includes rich editing capabilities. |
3 |
AutoCompleteTextView
The AutoCompleteTextView is a view that is similar to EditText, except that it shows a list of completion suggestions automatically while the user is typing. |
4 | Button
A push-button that can be pressed, or clicked, by the user to perform an action. |
5 | ImageButton
An ImageButton is an AbsoluteLayout which enables you to specify the exact location of its children. This shows a button with an image (instead of text) that can be pressed or clicked by the user. |
6 | CheckBox
An on/off switch that can be toggled by the user. You should use check box when presenting users with a group of selectable options that are not mutually exclusive. |
7 | ToggleButton
An on/off button with a light indicator. |
8 | RadioButton
The RadioButton has two states: either checked or unchecked. |
9 | RadioGroup
A RadioGroup is used to group together one or more RadioButtons. |
10 | ProgressBar
The ProgressBar view provides visual feedback about some ongoing tasks, such as when you are performing a task in the background. |
11 | Spinner
A drop-down list that allows users to select one value from a set. |
12 | TimePicker
The TimePicker view enables users to select a time of the day, in either 24-hour mode or AM/PM mode. |
13 | DatePicker
The DatePicker view enables users to select a date of the day. |
输入控件是应用程序用户界面中的交互式组件。 Android提供了可在UI中使用的多种控件,例如按钮,文本字段,搜索栏,复选框,缩放按钮,切换按钮等等。
如上一章所述,视图对象可能具有唯一的ID,该ID将在树中唯一地标识视图。 XML标记内的ID的语法是-
android:id="@+id/text_id"
要创建UI控件/视图/小部件,您将必须在布局文件中定义视图/小部件,并为其分配唯一的ID,如下所示:
然后最终创建Control对象的实例并从布局中捕获它,请使用以下命令-
TextView myText = (TextView) findViewById(R.id.text_id);