Android: Change the color of RadioButtons and checkboxes programmatically

前端 未结 6 1226
轮回少年
轮回少年 2020-12-15 08:11

I created RadioButton and CheckBox in LinearLayout programatically. But, now I want to change radio button\'s color and check boxes\'s

6条回答
  •  情书的邮戳
    2020-12-15 08:41

    You can create dynamic RadioButton like this:

    RadioButton male = new RadioButton(ReservationContact.this);
    male.setTextColor(Color.BLACK);
    male.setText("Male");
    male.setSelected(true);
    male.setId(0);
    

    This is used for changing default color of circle of RadioButton.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        male.setButtonTintList(ColorStateList.valueOf(ContextCompat.getColor(ReservationContact.this, R.color.background)));
    }
    male.setHighlightColor(getResources().getColor(R.color.background));
    

提交回复
热议问题