Ripple effect with custom xml?

I need to add ripple effect to all controls to add expectation to my application. Since my minimum api level is 18, so I cannot use <ripple>

in drawable xml. Also, all of my controls are custom made available as XML.

My custom Drawable for controls

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="2dp"/>
            <solid android:color="@color/border1"/>
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp"/>
            <corners android:radius="15dp"/>
            <solid android:color="@color/border2"/>
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp"/>
            <corners android:radius="15dp"/>
            <solid android:color="@color/border3"/>
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="2dp"/>
            <corners android:radius="15dp"/>
            <solid android:color="@color/border4"/>
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="2dp"/>
            <corners android:radius="15dp"/>
            <solid android:color="@color/border5"/>
        </shape>
    </item>

    <!-- Background -->
    <item>
        <shape>
            <solid android:color="@color/menu_bg"/>
            <corners android:radius="15dp"/>
        </shape>
    </item>
</layer-list>

      

If I use it android:background="?attr/selectableItemBackgroundBorderless"

for control, the ripple effect works well. but the problem is I have my own background for all my controls, so I cannot use attr / selectableItemBackgroundBorderless.

How do I use attr / selectableItemBackgroundBorderless with a custom highlighted background? I don't want to wrap the controls with frames or any other layouts. Is there another way?

Waiting for responses, Thanks in advance

+3


source to share


1 answer


Use foreground function, make clickable and focusable true.



<Button
   android:layout_width="match_parent"
   android:layout_height="wrap_content"                             
   android:background="@drawable/custom_button_disable_fill"
   android:foreground="?android:attr/selectableItemBackground"
   android:text="Login"
   android:saveEnabled="true"
   android:focusable="true"
   android:textAllCaps="false"
   android:textColor="@color/black_bold_medium"
   android:textSize="@dimen/text_large"
   app:font_name="@string/sourcesanspro_semi_bold"/>

      

+2


source







All Articles