0

how do you make the button click more visible like the press animation while having a xml drawable resource file set as a background on the button.when you add a background to the button, it isn't clear that whether the button has been pressed or not. So, any solution for that?

my drawable resource file

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#ca8924" />
            <corners
                android:radius="5dp"
                />

        </shape>


    </item>
    <item android:left="3dp" android:right="3dp" android:top="3dp" android:bottom="3dp">
        <shape android:shape="rectangle">
            <corners
                android:radius="5dp"
                />
            <solid android:color="#5c5656">

            </solid>
        </shape>
    </item>

</layer-list>

1 Answers1

1

Paste this code into an xml file under drawables folder.

<?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="10dp" />
        <stroke android:width="1dp" android:color="#33ff33" />
        <gradient android:angle="-90" android:startColor="#00ff00" android:endColor="#1aff1a"  />
    </shape>
</item>
<item android:state_focused="true">
    <shape android:shape="rectangle"  >
        <corners android:radius="10dp" />
        <stroke android:width="1dp" android:color="#33ff33" />
        <solid android:color="#1aff1a"/>
    </shape>
</item>
<item >
    <shape android:shape="rectangle"  >
        <corners android:radius="10dp" />
        <stroke android:width="1dp" android:color="#33ff33" />
        <gradient android:angle="-90" android:startColor="#66ff66" android:endColor="#4dff4d" />
    </shape>
</item>
</selector>
Suhas Wagre
  • 100
  • 1
  • 1
  • 9
  • a separate xml file or the background xml file that i'm using as a background on the button? – Javaid Hussain Jul 18 '17 at 11:12
  • you can set this file as background to your button. – Suhas Wagre Jul 18 '17 at 11:22
  • do i have to write it in a separate xml file or the background xml file that i'm using as a background on the button? – Javaid Hussain Jul 18 '17 at 11:26
  • just create a new file by right click on drawable->Drawable resource file , name the file and paste the above code in that newly created drawable file...then set that file to the background of button – Suhas Wagre Jul 18 '17 at 11:30
  • and yeah i want to use layer-list not selector what do i do now it just works with selector!!!. And sorry if i'm irritating you – Javaid Hussain Jul 18 '17 at 11:42
  • i think this link might help you in this case https://stackoverflow.com/questions/8339529/android-using-layer-list-for-button-selector...btw i'm not irritated you are always welcome for healthy discussion. – Suhas Wagre Jul 18 '17 at 11:48