Ripple Effect in Android for Button

Ripple Effect in Android for Button - Hello friend inabnomaniiyaha, In the article that you read this time with the title Ripple Effect in Android for Button, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel android-example,what we write you can understand. Alright, happy reading.

Judul : Ripple Effect in Android for Button
link : Ripple Effect in Android for Button

Baca juga


Ripple Effect in Android for Button

Ripple Effect in Android for Button

First of all we need to create a file colors.xml (if not present) in app -> res -> values to define all the necessary colors

colors.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <color name="colorPrimary">#3F51B5</color>

    <color name="colorPrimaryDark">#303F9F</color>

    <color name="colorAccent">#FF4081</color>


    <color name="white">#FFFFFF</color>

    <color name="colorRipple">#A9A9F5</color>

</resources>

Now we need to create a drawable resource file and name it ripple_effect as shown below

ripple_effect.xml 

<?xml version="1.0" encoding="utf-8"?>

<ripple

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:color="@color/colorRipple">     <!-- ripple color -->


    <!-- for Button -->

    <item>

        <shape android:shape="rectangle">

            <corners android:radius="3dp" />

            <solid android:color="@color/colorPrimary"/>

        </shape>

    </item>


</ripple>

Add the below code to your ripple_effect.xml file

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:state_pressed="true">

        <shape android:shape="rectangle">

            <corners android:radius="3dp" />

            <solid android:color="@color/colorRipple" />

        </shape>

    </item>

    <item android:state_focused="true">

        <shape android:shape="rectangle">

            <corners android:radius="3dp" />

            <solid android:color="@color/colorPrimary" />

        </shape>

    </item>

    <item>

        <shape android:shape="rectangle">

            <corners android:radius="3dp" />

            <solid android:color="@color/colorPrimary" />

        </shape>

    </item>


</selector>

Now add a Button, LinearLayout and FrameLayout to your layout file and set background as drawable resource file ripple_effect.xml

<Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/refresh"

        android:textColor="@color/white"

        android:layout_gravity="center_horizontal"

        android:background="@drawable/ripple_effect" />

Adding LinearLayout

    <LinearLayout

        android:id="@+id/llInviteOthers"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:padding="8dp"

        android:clickable="true"

        android:background="@drawable/ripple_effect">


        <ImageView

            android:layout_width="20dp"

            android:layout_height="20dp"

            android:src="@mipmap/ic_refresh"/>


        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="@string/refresh"

            android:layout_marginLeft="5dp"

            android:layout_marginStart="5dp"

            android:textColor="@color/white"

            android:layout_gravity="center_vertical"/>


    </LinearLayout>

Adding FrameLayout

    <FrameLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:padding="8dp"

        android:clickable="true"

        android:background="@drawable/ripple_effect">


        <ImageView

            android:layout_width="20dp"

            android:layout_height="20dp"

            android:src="@mipmap/ic_refresh"/>

        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="@string/refresh"

            android:layout_marginLeft="25dp"

            android:layout_marginStart="25dp"

            android:textColor="@color/white"

            android:layout_gravity="center_vertical"/>


    </FrameLayout>

Screen:

Ripple Effect in Android for Button



That's the articleRipple Effect in Android for Button

That's it for the article Ripple Effect in Android for Button this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleRipple Effect in Android for Button with link addresshttps://inabnonapudyawanabing.blogspot.com/2020/11/ripple-effect-in-android-for-button.html

0 Response to "Ripple Effect in Android for Button"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...