Button Pressed Effect Style on Android

In this blog post, I would like explain how to create a Button Pressed Effect in Android.

To do this, you need to remember three thing:

1st -normal view, 2nd -focused view and 3rd -clicked view

  1. Create a new layout in res\layout,(i am naming it as ‘button_style.xml’).
  2. Place following code into new layout i.e. in button_style.xml.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_pressed"
          android:state_pressed="true" />
    <item android:drawable="@drawable/button_focused"
          android:state_focused="true" />
    <item android:drawable="@drawable/button_normal" />

Use 3 different Images or Colors or Gradients to Style your Button.

3. and in your code in res/layout/main.xml or in your button’s code


4. Use this Code Snippet to Button, TextView, ImageView and EditText too.

Tips to remember:

Leave a Reply

Your email address will not be published. Required fields are marked *