Any way to change the color of a radio button?

前端 未结 3 582
梦如初夏
梦如初夏 2020-12-17 17:21

I\'m working on an android form with a radio group containing a set of radio buttons. From what I can tell there is no way to set the color a radio button highlights when yo

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 18:01

    Use AppCompatRadioButton instead of RadioButton.

      
    

    To change the color programatically do this:

    ColorStateList colorStateList = new ColorStateList(
                    new int[][]{
                            new int[]{android.R.attr.state_enabled} //enabled
                    },
                    new int[] {getResources().getColor(R.color.colorPrimary) }
            );
    
    AppCompatRadioButton radioButton = (AppCompatRadioButton) findViewById(R.id.rb);
    radioButton.setSupportButtonTintList(colorStateList);
    

提交回复
热议问题