The following table lists the commonly used components in an Android Kotlin user interface:
| Component | Description | Reference Link |
|---|---|---|
| TextView | Displays text on the screen | TextView Reference |
| EditText | Allows the user to input text | EditText Reference |
| ImageView | Displays an image on the screen | ImageView Reference |
| Button | Triggers an action when the user taps it | Button Reference |
| ImageButton | A button that displays an image | ImageButton Reference |
| CheckBox | Allows the user to select one or more options | CheckBox Reference |
| RadioButton | Allows the user to select one option from a list | RadioButton Reference |
| Spinner | Displays a dropdown list of options | Spinner Reference |
| ProgressBar | Indicates the progress of an ongoing task | ProgressBar Reference |
| SeekBar | Allows the user to select a value from a range | SeekBar Reference |
| Switch | Allows the user to toggle a setting on or off | Switch Reference |
| DatePicker | Allows the user to select a date | DatePicker Reference |
| TimePicker | Allows the user to select a time | TimePicker Reference |
| RatingBar | Allows the user to rate something on a scale | RatingBar Reference |
| VideoView | Displays a video on the screen | VideoView Reference |
| WebView | Displays a webpage on the screen | WebView Reference |
| RecyclerView | Displays a list of items that can be scrolled | RecyclerView Reference |
| CardView | Displays content in a card-like format | CardView Reference |
| BottomNavigationView | Allows the user to switch between app views | BottomNavigationView Reference |
| TabLayout | Displays tabs that the user can switch between | TabLayout Reference |
Here are some sample code snippets for each of the components listed in the table:
val textView = findViewById<TextView>(R.id.textView)
textView.text = "Hello, World!"
val editText = findViewById<EditText>(R.id.editText)
val text = editText.text.toString()
val imageView = findViewById<ImageView>(R.id.imageView)
val imageResource = R.drawable.my_image
imageView.setImageResource(imageResource)
val button = findViewById<Button>(R.id.button)
button.setOnClickListener {
// Do something when the button is clicked
}
val imageButton = findViewById<ImageButton>(R.id.imageButton)
imageButton.setOnClickListener {
// Do something when the image button is clicked
}
val checkBox = findViewById<CheckBox>(R.id.checkBox)
val isChecked = checkBox.isChecked
val radioButton1 = findViewById<RadioButton>(R.id.radioButton1)
val radioButton2 = findViewById<RadioButton>(R.id.radioButton2)
val selectedRadioButton = findViewById<RadioButton>(radioGroup.checkedRadioButtonId)