更改Android Appcompat单选按钮的涟漪效果中心位置

9

我尝试使用AppCompactRadioButton为安卓做一个RTL收音机按钮 -将收音机放在右侧-,并且我通过android:drawableRight和设置android:button="@null"来实现了这个目的,所以我的最终视图是我想要的,最终代码如下:

<android.support.v7.widget.AppCompatRadioButton
            android:id="@+id/radio_man"
            style="@style/app_font"
            android:layout_width="0dp"
            android:layout_height="@dimen/edit_text_height"
            android:layout_weight="1"
            android:button="@null"
            android:drawableRight="@drawable/form_radiobutton"
            android:minHeight="33dp"
            android:onClick="onSexRadioButtonClicked"
            android:text="@string/hint_man" />

单选按钮上的错误涟漪

我的问题是如何更改涟漪效果的中心位置,因为我将按钮设置为null,导致涟漪效果中心位置在单选按钮的中心,如上图所示,并且用户不希望在那里看到涟漪。我尝试将layout_direction设置为RTL,但没有解决问题。

我还要提到,我也尝试使用以下涟漪可绘制对象来修复此问题,但没有任何变化,问题仍然存在。

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/transparent">
<item>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:drawable="@drawable/btn_radio_activated"
            android:state_checked="true" />
        <item android:drawable="@drawable/btn_radio_deactive" />
    </selector>
</item>
</ripple>

长话短说,有没有想法改变 Android Appcompat 单选按钮的涟漪效果中心位置?

你能找到一个解决方案吗? - ReZa
@ReZa,不好意思,我没有找到任何解决方案。 - Ali Abdolahi
2个回答

4
我可以通过将RadioButton的背景更改为透明色来成功消除波纹效果,代码如下:
  android:background="@android:color/transparent"

我还没有尝试过,但我猜你可以设置一个带有左填充的可绘制对象来解决这个问题。

目前还没有找到任何解决方案,目前最好的答案是去除涟漪效果... - Mohamad MohamadPoor
感谢,那个属性很有帮助。 - 4xMafole

2
我认为你需要的是在RadioButtons中添加android:background="?selectableItemBackground",这将覆盖错误的涟漪效果。"Original Answer"翻译成"最初的回答"。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接