【发布时间】:2019-07-28 00:26:29
【问题描述】:
我试图将选择器提供给android:button 的RadioButton,但无法在预览和真实设备中显示该按钮,我的目标是使android:button 成为自定义。
我必须RadioGroup 和两个RadioButton。
我也试过这个解决方案https://stackoverflow.com/a/12432722/6869491
但仍然无法得到想要的解决方案。
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_25"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="@id/sub_const"
app:layout_constraintEnd_toEndOf="@id/sub_const"
app:layout_constraintStart_toStartOf="@id/sub_const"
app:layout_constraintTop_toBottomOf="@id/pay_amt_et">
<RadioButton
style="@style/MyRadioButtonStyle"
android:id="@+id/manual_rb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/manual"
android:textColor="@color/textcolor"
android:textSize="@dimen/fontsize_16"
/>
<RadioButton
style="@style/MyRadioButtonStyle"
android:id="@+id/recurring_rb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Recuring"
android:textColor="@color/textcolor"
android:textSize="@dimen/fontsize_16"
/>
</RadioGroup>
这里是单选按钮选择器,即radio_btn_selector。
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/radio_btn_un_selected" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/radio_btn_un_selected" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/radio_btn_un_selected" />
<item android:state_checked="false" android:drawable="@drawable/radio_btn_un_selected" />
<item android:state_checked="true" android:drawable="@drawable/radio_btn_active" />
这里是 radio_btn_active。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/colorWhite" />
<stroke
android:width="@dimen/padding_2"
android:color="@color/grey_darker" />
</shape>
</item>
<item
android:bottom="@dimen/padding_30"
android:end="@dimen/padding_30"
android:start="@dimen/padding_30"
android:top="@dimen/padding_30">
<shape android:shape="oval">
<solid android:color="@color/primary_edtext_light" />
</shape>
</item>
</layer-list>
这是 radio_btn_un_selected。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorWhite" />
<stroke
android:width="@dimen/padding_2"
android:color="@color/grey_darker" />
</shape>
还有鉴于风格。
<style name="MyRadioButtonStyle"
parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">@drawable/radio_btn_selector</item>
</style>
我做错了什么请指导我。
【问题讨论】:
-
我也尝试过该解决方案,但无法获得解决方案
标签: android android-layout radio-button