Android 设计为普通按钮的RadioButton
我正在尝试将我的单选按钮设计为普通按钮,并支持按钮上的颜色变化,单击其中一个按钮时会产生涟漪效果 现在发生的事情是,所有按钮都是灰色的,当它们被点击时,它们会在紫色中波动,但不会永久性地将其颜色更改为紫色——这就是我试图解决的问题 这就是他现在的样子 whatever.xml中的RadioButtonAndroid 设计为普通按钮的RadioButton,android,android-styles,android-radiobutton,Android,Android Styles,Android Radiobutton,我正在尝试将我的单选按钮设计为普通按钮,并支持按钮上的颜色变化,单击其中一个按钮时会产生涟漪效果 现在发生的事情是,所有按钮都是灰色的,当它们被点击时,它们会在紫色中波动,但不会永久性地将其颜色更改为紫色——这就是我试图解决的问题 这就是他现在的样子 whatever.xml中的RadioButton <RadioButton style="@style/Widget.AppCompat.Button" android:id="@+id/product_size2"
<RadioButton
style="@style/Widget.AppCompat.Button"
android:id="@+id/product_size2"
android:layout_width="48dp"
android:layout_height="48dp"
android:text="S"
android:button="@null"
android:textColor="@color/material_light_white"/>
<item name="android:colorButtonNormal">@color/material_grey_700</item>
<item name="android:colorControlHighlight">@color/material_purple_500</item>
style.xml中的相关项
<RadioButton
style="@style/Widget.AppCompat.Button"
android:id="@+id/product_size2"
android:layout_width="48dp"
android:layout_height="48dp"
android:text="S"
android:button="@null"
android:textColor="@color/material_light_white"/>
<item name="android:colorButtonNormal">@color/material_grey_700</item>
<item name="android:colorControlHighlight">@color/material_purple_500</item>
@color/material\u grey\u 700
@颜色/材质\u紫色\u 500
我希望按钮在选择时保持紫色-解决方案?
radiobutton\u background.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="@color/material_purple_500" />
<item android:state_checked="false" android:drawable="@color/material_grey_700" />
</selector>
我想你应该使用一个背景状态选择器来完成这项任务。你能详细说明一下吗?好的,我会尝试回答你的问题。你有没有尝试过为按钮创建一个自定义的xml样式,使其具有不同的状态?我看到了这些xml封装的答案-我认为一定有一个更优雅的解决方案不起作用,发生的是背景覆盖了样式,有效地扼杀了样式(创建一个没有标高的立方体)并且没有涟漪效应