Different attributes of RadioButton widget
XML Attributes | Description |
---|---|
android:id | Used to uniquely identify the control |
android:gravity | Used to specify how to align the text like left, right, center, top, etc. |
android:checked | Used to specify the current state of radio button |
android:onClick | It’s a name of the method to invoke when the radio button clicked. |
android:textSize | Used to set size of the text. |
android:textColor | Used to set color of the text. |
android:textStyle | Used to set style of the text. For example, bold, italic, bolditalic etc. |
android:maxWidth | Used to make the view be at most this many pixels wide. |
android:minWidth | Used to make the view be at least this many pixels wide. |
android:background | Used to set the background of the radio button control. |
android:visibility | Used to control the visibility. |
RadioButton in Kotlin
Android Radio Button is bi-state button which can either be checked or unchecked. Also, it’s working is same as Checkbox except that radio button can not allow to be unchecked once it was selected.
Generally, we use RadioButton controls to allow users to select one option from multiple options.
By default, the RadioButton in OFF(Unchecked) state but we can change the default state of RadioButton by using android:checked attribute.
Following steps to create new project-
- Click on File,then New => New Project.
- Then, check Include Kotlin Support and click next button.
- Select minimum SDK, whatever you need.
- Select Empty activity and then click finish.
Contact Us