Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change android Ripple effect center position for android Appcompat radio button

I tried to make RTL radio -Put radio on right side- button for android with AppCompactRadioButton, and i achieved this with android:drawableRight and set android:button="@null" so my final view is what i wanted and final code is this:

<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" />

wrong ripple on radio button

But my question is how to to change ripple effect center position, because i set button to null, the ripple effect center poisiton is in center of radio button like image above and its not expected by user to see ripple there. i tried to set layout_direction to RTL, but nothing fixed.

I have to mention that i also tried to fix this problem with ripple drawable like below but nothing changed and problem is still there.

<?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>

Long story short, is there any idea to change android Ripple effect center position for android Appcompat radio button?

like image 850
Ali Abdolahi Avatar asked Apr 25 '16 06:04

Ali Abdolahi


2 Answers

I can succesfully erase the ripple effect by changing the background of the RadioButton to transparent like this:

  android:background="@android:color/transparent"

I didn't yet tried but i guess you can set a drawable with left padding to overcome this problem.

like image 164
Oguz Ozcan Avatar answered Oct 27 '22 02:10

Oguz Ozcan


I think what you're looking for is

android:background="?selectableItemBackground"

in your RadioButtons. That will overwrite the wrong ripple effect.

like image 28
sergiosua Avatar answered Oct 27 '22 01:10

sergiosua