applying rounded corners to checkbox and radiogroup android

Viewed 22

I have checkbox and radiogroup which are currently square shape. I want to apply rounded corners or edges. The checkbox and radiogroup change colors on selection and deselecttion. I tried applying rounded corners through xml and coding programatically. The checkbox and radiogroup become unclickable. Both metthods not working. What could be the solution

 @Override
public void onBindViewHolder(@NonNull final OptionsViewHolder holder, int p) {

    final int position = p;


    RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.MATCH_PARENT);
    final ArrayList<SlotOption> slotOptionArrayList = daySlotModelArrayList.get(position).getOpt();


    holder.dayNameCheckbox.setText(daySlotModelArrayList.get(position).getDayName());
    holder.dayNameCheckbox.setTag(daySlotModelArrayList.get(position).getDayId());

       GradientDrawable gd = new GradientDrawable();
    gd.setCornerRadius(20);
    holder.dayNameCheckbox.setBackground(gd);

    for (int i = 0; i < slotOptionArrayList.size(); i++) {
        RadioButton radioButton = new RadioButton(holder.item_view.getContext());
        radioButton.setText(slotOptionArrayList.get(i).getOptionName());
        radioButton.setTag(slotOptionArrayList.get(i).getOptionId());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            radioButton.setBackground(holder.item_view.getContext().getDrawable(R.drawable.button_style));
        }
        layoutParams.setMargins(0, 0, 4, 0);
        radioButton.setPadding(3, 0, 3, 0);
        radioButton.setLayoutParams(layoutParams);
        radioButton.setGravity(Gravity.CENTER);
        radioButton.setEnabled(false);
        radioButton.setTextColor(holder.item_view.getResources().getColor(R.color.white));
        radioButton.setMaxWidth(120);
        radioButton.setButtonDrawable(null);
        holder.slotradiogroup.addView(radioButton);


    }

XML FILE

<CheckBox
    android:id="@+id/dayButton"
    style="@style/checkBoxButtonStyle"
    android:layout_width="90dp"
    android:paddingLeft="2dp"
    android:button="@null"
    android:layout_marginRight="10dp"
    android:layout_height="match_parent"
    android:background="@drawable/rounded_corner"/>    
0 Answers
Related