This blog is about creating effects for a Button in Android:-
First create a xml file named button_pressed.xml in drawable folder and copy the below code in that file.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape>
<solid
android:color="#2e2e2e" />
<stroke
android:width="2dp"
android:color="#ffffff" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#2e2e2e"
android:endColor="#2e2e2e"
android:angle="270" />
<corners
android:radius="7dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
Then, add an attribute for your button in the specific layout file.
<Button
android:id="@+id/userLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_pressed"
android:text="Login"
android:textColor="#ffffff"
android:textSize="18sp" />
Happy coding.
First create a xml file named button_pressed.xml in drawable folder and copy the below code in that file.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape>
<solid
android:color="#2e2e2e" />
<stroke
android:width="2dp"
android:color="#ffffff" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#2e2e2e"
android:endColor="#2e2e2e"
android:angle="270" />
<corners
android:radius="7dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
Then, add an attribute for your button in the specific layout file.
<Button
android:id="@+id/userLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_pressed"
android:text="Login"
android:textColor="#ffffff"
android:textSize="18sp" />
Happy coding.