I am trying to create controls with code, I was able to create them but my problem is that when creating them they do not adopt my custom style that I am using with material design properties. I am attaching an image where I have created controls manually with xml design and they adopt the material design style without problems, but at the bottom I created 3 controls (Textview, EditText and RadioButton) with java code which have not adopted the style. The problem happens in Api 19 or lower, in Api 21 and up I don't have this problem.
I did everything they told me and I don't find results, it's still the same, I leave my code that I'm using.
package com.ejemplo.probandoo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewGroup hourButtonLayout = (ViewGroup) findViewById(R.id.radio_group);
final RadioButton[] rb = new RadioButton[5];
RadioGroup rg = new RadioGroup(this);
//rg.setOrientation(RadioGroup.VERTICAL);
for(int i=0; i<5; i++){
rb[i] = new RadioButton(this);
rb[i].setText("foo bar");
rb[i].setId(i + 100);
rg.addView(rb[i]);
}
hourButtonLayout.addView(rg);
}}
That's my code and the result is the same it doesn't adopt my custom style: