In my code, I programmatically add input elements like radioButtons, checkboxes, etc. The problem is that the style of these elements is not the default style that you would get when you add, say, radioButton via xml. (It looks really white and almost transparent on the white background of the application. Itβs a bit like transparency) Also, the EditText elements that I add have the same style, and if you enter something into them, the text is too big and a bit overlaps the text string. Therefore, I assume that it all boils down to somehow giving these elements the default style of how they look when they are defined through xml.
A sample of my code is as follows:
RadioGroup radioGroup = new RadioGroup(mContext); radioGroup.setLayoutParams(fullWidthWrapHeight); for (int i = 0; i < arg0.getOptions().size(); i++){ RadioButton radioButton = new RadioButton(mContext, null); radioButton.setPadding(padding16dp , padding8dp, padding16dp, padding8dp); radioButton.setText(arg0.getOptions().get(i).getText()); radioButton.setLayoutParams(wrapBoth); radioButton.setGravity(Gravity.CENTER_HORIZONTAL); radioButton.setTextAppearance(mContext, R.style.Default_Text); radioGroup.addView(radioButton); }
My target lvl API is 21 (Lollipop)
source share