Setting styles of programmatically added Views

前端 未结 2 604
野性不改
野性不改 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条回答
  •  萌比男神i
    2021-01-18 08:01

    As for me, it has been successfully solved just by that way:

    Activity.java

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    

    ...

        { 
            RadioButton rb = (RadioButton) inflater.inflate(R.layout.radio_butt, null);
            rb.setText(this_currency_option);
            rb.setTextColor(context.getResources().getColor(R.color.colorWhite));
            rb.setId(100 + i);
            radioGroup.addView(rb);
        }
    

    radio_butt.xml

    
    
    

    slyles.xml

    
    

提交回复
热议问题