Change color of a radio button

前端 未结 11 1866
死守一世寂寞
死守一世寂寞 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:37

    To change RadioButton button colour programmatically, and works on api level < 21, should use AppCompatRadioButton instead of RadioButton:

    (otherwise will warn setbuttontintlist requrie api level 21)

    import android.support.v7.widget.AppCompatRadioButton;
    
    AppCompatRadioButton radioButton = new AppCompatRadioButton(getActivity());
    radioButton.setSupportButtonTintList(
            ContextCompat.getColorStateList(getActivity(),
            R.color.single_choice_state_list));
    

    single_choice_state_list.xml

    
        
        
    
    

提交回复
热议问题