Java “以编程方式”复选框未获取样式
我正在以编程方式创建一个Java “以编程方式”复选框未获取样式,java,android,Java,Android,我正在以编程方式创建一个复选框和一个单选按钮,但是在某些设备中,文本被画在选项上,它们变成黑色。 请帮我解决这个问题 复选框的代码: LinearLayout linearLayout = new LinearLayout(context); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP
复选框
和一个单选按钮
,但是在某些设备中,文本被画在选项上,它们变成黑色。
请帮我解决这个问题
复选框的代码:
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setLayoutParams(new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
CheckBox cb = new CheckBox(context);
cb.setId(opcao.getId());
cb.setText(opcao.getValor());
if (UtilSystem.isNotNull(selecionados) && selecionados.size()>0){
for (Integer cdSelected: selecionados){
if (cdSelected.equals(opcao.getId())){
cb.setChecked(true);
}
}}
cb.setPadding(0,15,0,15); cb.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.selector_transparent_grey));
单选按钮代码
RadioGroup rg = (RadioGroup) view.findViewById(R.id.rgChecklist);
for (final ChecklistTemplatePerguntaOpcao opcao: opcoes){
RadioButton rb = new RadioButton(context);
rb.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
rb.setId(opcao.getId());
rb.setText(opcao.getValor());
if (UtilSystem.isNotNull(selected) && opcao.getId().equals(selected)){
rb.setChecked(true);
}
rb.setPadding(0,15,0,15);
rb.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.selector_transparent_grey));
rg.addView(rb);
}
例如:
您能添加XML文件吗?一切看起来都是正常的。也许你可以分享一些其他的代码,因为问题不在这里。你能添加XML文件吗?一切看起来都应该是这样的。也许您可以共享一些其他代码,因为问题不在这里。