Change color of a radio button

前端 未结 11 1862
死守一世寂寞
死守一世寂寞 2020-12-10 02:11

I am developing an quiz based app. There will be 1 question and 4 option(radio buttons). If user select any wrong answer then I want to turn that radio button color to Red.

11条回答
  •  眼角桃花
    2020-12-10 02:57

    //get radio button reference from layout
    RadioButton raPrivate = (RadioButton) layout.findViewById(R.id.radioPrivate);
    //parse textColor from string hex code
    int textColor = Color.parseColor("#000000");
    //set textcolor to radioButton
    raPrivate.setButtonTintList(ColorStateList.valueOf(textColor));
    

    u can only assing ColorStateList objets as color for the radioButton, if u use valueOf it will only use one color.

    Hope this helps :>

提交回复
热议问题