gpt4 book ai didi

android从文本中直接设置单选按钮

转载 作者:行者123 更新时间:2023-11-29 00:05:30 25 4
gpt4 key购买 nike

早上好!

我想直接从他的文本中设置一个单选按钮。我在这里看到了这样的解决方案:

 <RadioButton
android:drawablePadding="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radioButton"
android:drawableRight="@android:drawable/btn_radio"
android:button="@null"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:paddingStart="18dp"
android:paddingEnd="12dp"
android:textColor="@color/DefaultGrey"
android:textSize="14sp"
android:checked="false" />

这直接从他的文本中设置了单选按钮,但我不喜欢我用这段代码获得的替代单选按钮的样式。

有没有办法使用默认的单选按钮样式?

最佳答案

Kotlin 程序化解决方案:

private fun createDrawableRightRadioButton(message: String): RadioButton {

val radioButton = RadioButton(context)
radioButton.layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)

radioButton.setText(message)
radioButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.resources.getDimension(R.dimen.text_medium)); //<dimen name="text_medium">14sp</dimen>
radioButton.setTextColor(ContextCompat.getColorStateList(context, R.color.radio_grey_text_selector))
radioButton.typeface = Typeface.create("roboto", Typeface.NORMAL)

radioButton.layoutDirection = View.LAYOUT_DIRECTION_RTL
radioButton.setButtonDrawable(0) // for removing default drawable
radioButton.setCompoundDrawablePadding(10)
radioButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.gostyle_radio_button_selector, 0); // for adding drawable on the right
radioButton.gravity = Gravity.CENTER_VERTICAL

return radioButton

}

关于android从文本中直接设置单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34082462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com