Radio Button


Radio Button


In Android, there is the option of creating a RadioButton by dragging from the palette and dropping it to the work area. This is the traditional way, we also have the option to create the RadioButton dynamically through a given code. This can be done by using, android.view.ViewGroup.LayoutParams, which is responsible for configuring the height and width of the view setOnCheckedChangeListener() method, which is part of the RadioGroup Class. The RadioGroup class is used for creating radio buttons.

There are multiple sites from where we can get the custom logo for the custom checkboxes as shown in the above image. The first step will be to obtain these images from the custom logo sites, and then use Android Asset Studio for developing drawables in different design sizes, something like hdpi or mdpi. Once a drawable is developed we can include them in our project, which is there in Android Studio. Once the drawables are available, it is time to develop the UI XML Interface that will have the checkbox. In the next step, go to your drawable resource location, and there create a custom XML file, with the code given below.

The following XML files define the Activity for the Radio Button.

Here the functionality of “Main Activity” needs to be described in a separate file, that will describe the behavior of the Radio button. It can be in standard Java, where the android packages can be imported. The RadioButton can be completely customized as well using drawable, just like we did for the checkbox in the previous section.