Android 自定义安卓主题不';不适用于动态创建的视图

Android 自定义安卓主题不';不适用于动态创建的视图,android,Android,我正在Android中基于动态内容以编程方式创建RadioButtons。为了模拟这种情况,我创建了一个makeRadioButton(string)方法。当我动态地向布局添加视图时,它不会采用我在Android清单中定义的自定义主题 下面是一段代码片段: public void makeRadioButton(String name) { RadioButton rbTmp = new RadioButton(getApplicationContext()); rbTmp.se

我正在Android中基于动态内容以编程方式创建
RadioButton
s。为了模拟这种情况,我创建了一个
makeRadioButton(string)
方法。当我动态地向布局添加视图时,它不会采用我在Android清单中定义的自定义主题

下面是一段代码片段:

public void makeRadioButton(String name) {
    RadioButton rbTmp = new RadioButton(getApplicationContext());
    rbTmp.setText(name);
    rbTmp.setTextColor(getResources().getColor(R.color.black));
    rbTmp.setPadding(50, 50, 50, 50);
    getApplicationContext().setTheme(R.style.CustomAppTheme);
    rgRadioGroup.addView(rbTmp);
}
下面是一个屏幕截图:

第一个
单选按钮
通过GUI添加到布局中。第二个是使用上面的代码动态添加的。它们都是同一个
放射组的一部分
,因此当一个被选中时,另一个被取消选中,正如预期的那样


我似乎找不到任何东西可以让我以编程方式将主题设置为单个视图,我希望我的动态添加视图能够在Android清单中获取应用程序的主题集。

尝试使用单选按钮作为上下文的一部分的任何活动,而不是应用程序上下文。这很有效,非常感谢!