Setting styles of programmatically added Views

前端 未结 2 614
野性不改
野性不改 2021-01-18 07:00

In my code, I add input elements like radioButtons, checkboxes etc to my Layout programmatically. The problem is, that the style of those elements is not the default style t

2条回答
  •  遇见更好的自我
    2021-01-18 07:52

    You can pass a style defined inside styles.xml as an argument of a View constructor. So considering your example, you would have to call:

    RadioButton radioButton = new RadioButton(mContext, null, R.attr.radioButtonStyle);
    

    then add custom attribute inside attrs.xml

    
    

    and inside your application theme in styles.xml add

    @style/YourRadioButtonStyle
    

    YourRadioButtonStyle is custom radio button style defined in styles.xml

提交回复
热议问题