移除RadioButton的涟漪效应,android?

移除RadioButton的涟漪效应,android?,android,Android,我定制了一个RadioButton,用于在右侧添加RadioButton图像 <RadioButton android:layout_margin="20dp" android:drawableRight="@drawable/custom_btn_radio" android:button="@null" android:layout_width="match_

我定制了一个RadioButton,用于在右侧添加RadioButton图像

<RadioButton
                android:layout_margin="20dp"
                android:drawableRight="@drawable/custom_btn_radio"
                android:button="@null"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Invite Only"/> 

自定义_btn_radio.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/check_box" android:state_checked="false"/>
    <item android:drawable="@drawable/close_btn" android:state_checked="true"/>
</selector>

但是,单选按钮的涟漪效应也扩大了。如何消除单选按钮的涟漪效应?以及如何定制涟漪效应


先谢谢你

使单选按钮背景透明

android:background="#ffffffff"


colorControlHighlight
colorControlActivated
设置为透明色为我解决了这个问题:

<style name="transparent_theme">
    <item name="colorControlHighlight">@android:color/transparent</item>
    <item name="colorControlActivated">@android:color/transparent</item>
</style>


@android:彩色/透明
@android:彩色/透明
在“如何自定义涟漪效果”部分,使用Material Components library v1.1.0,默认情况下,背景是一个
RippleDrawable
,其颜色设置为2种颜色的
ColorStateList
:处于启用和选中状态的26 alpha(#十六进制中的A1)
colorControlActivated
,对于默认状态,阿尔法白色或黑色取决于您的主题是浅色(#1F000000)还是深色(#33FFFFFF)。我只是通过检查调试器中
MaterialCheckBox
的背景来检索此信息

您只需使用
setColor
方法覆盖
RippleDrawable
的颜色即可。例如,如果希望在使用DayNight主题时仅更改涟漪效果的强调色部分,则可以运行以下Kotlin代码示例:

private val RIPPLE_ENABLED_CHECKED_STATES = arrayOf(
        intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked),
        intArrayOf())

fun Int.withAlpha(alpha: Int): Int {
    require(alpha in 0..0xFF)
    return this and 0x00FFFFFF or (alpha shl 24)
}

fun CompoundButton.changeCheckedRippleColor(@ColorInt color: Int) {
    val defaultAlphaColor= if (context.resources.configuration.uiMode and 
                Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
            Color.WHITE.withAlpha(51)
        else
            Color.BLACK.withAlpha(31)
    (background as? RippleDrawable)?.setColor(ColorStateList(RIPPLE_ENABLED_CHECKED_STATES,
                intArrayOf(color.withAlpha(26), defaultAlphaColor)))
}

只需将RadioButton background设置为透明。谢谢@Harry i设置android:background=“#ffffffff”。有没有其他方法可以设置背景透明?@android:color/transparent再次感谢@Harryhow将其添加到我的RadioButton?这对我有用->android:backgroundTint=“@android:color/transparent”第一种方法将其设置为完全不透明的白色
<style name="transparent_theme">
    <item name="colorControlHighlight">@android:color/transparent</item>
    <item name="colorControlActivated">@android:color/transparent</item>
</style>
private val RIPPLE_ENABLED_CHECKED_STATES = arrayOf(
        intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked),
        intArrayOf())

fun Int.withAlpha(alpha: Int): Int {
    require(alpha in 0..0xFF)
    return this and 0x00FFFFFF or (alpha shl 24)
}

fun CompoundButton.changeCheckedRippleColor(@ColorInt color: Int) {
    val defaultAlphaColor= if (context.resources.configuration.uiMode and 
                Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
            Color.WHITE.withAlpha(51)
        else
            Color.BLACK.withAlpha(31)
    (background as? RippleDrawable)?.setColor(ColorStateList(RIPPLE_ENABLED_CHECKED_STATES,
                intArrayOf(color.withAlpha(26), defaultAlphaColor)))
}