【发布时间】:2020-03-07 00:38:47
【问题描述】:
我正在尝试在单选按钮的左侧添加填充。但实际上在drawable和text之间添加了padding。
我创建单选按钮的方法:
private RadioButton createRadioButton(String text) {
RadioButton btn = new RadioButton(requireContext());
btn.setId(View.generateViewId());
btn.setText(text);
btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
btn.setTextColor(answerButtonColor);
btn.setButtonTintList(answerButtonColor);
int pxHorizontal = Utils.convertDpToPx(requireContext(), 24);
int pxVertical = Utils.convertDpToPx(requireContext(), 16);
btn.setPadding(pxHorizontal, pxVertical, pxHorizontal, pxVertical);
btn.setLayoutParams(new RadioGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
return btn;
}
有没有办法在单选按钮的左侧添加填充?
【问题讨论】:
-
您可以在其中创建一个带有 MaterialRadioButton 的布局,然后在您的代码中添加该布局。通过这种方式,您可以根据需要设置单选按钮的样式。适合你的工作吗?
标签: java android radio-button