Android 右对齐文本单选按钮可编程
嗨,我需要创建一个自定义单选按钮类,每个状态有两个不同的图片和RTL文本。我制作了按钮,但无法为api 8和更高版本制作文本RTL。如果有人能帮助我,我会很高兴的Android 右对齐文本单选按钮可编程,android,constructor,right-to-left,text-alignment,android-radiobutton,Android,Constructor,Right To Left,Text Alignment,Android Radiobutton,嗨,我需要创建一个自定义单选按钮类,每个状态有两个不同的图片和RTL文本。我制作了按钮,但无法为api 8和更高版本制作文本RTL。如果有人能帮助我,我会很高兴的 RadioGroup crdg=(RadioGroup)findviewbyd(R.id.RadioGroup 11) 制作单选按钮 rdbt1 = new RadioButton(new ContextThemeWrapper( getApplicationContext(), R.style.styleNa
RadioGroup crdg=(RadioGroup)findviewbyd(R.id.RadioGroup 11)代码>
制作单选按钮
rdbt1 = new RadioButton(new ContextThemeWrapper(
getApplicationContext(), R.style.styleName));
rdbt1.setButtonDrawable(android.R.color.transparent);
rdbt1.setText("for example(RTL text)");
将RadioButton添加到单选组
crdg.addView(rdbt1);
样式名是
@空的
@可绘图/rdb\u问题\u选择器
您只需将重力设置为gravity.END
例如:
RadioButton tempRadioButton = new RadioButton(this);
tempRadioButton.setGravity(Gravity.END);
tempRadioButton.setText("for example(RTL text)");
这将告诉Android将文本与RTL语言视图的“结尾”对齐。添加此选项
forcertlif支持()
在oncreate()中
你也可以发布xml吗?我不使用xml,因为我想用java代码创建单选按钮
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void forceRTLIfSupported()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}