How to apply shape and selector simultaneously for Button?

Khawar Raza picture Khawar Raza · Sep 30, 2011 · Viewed 61.4k times · Source

I have applied a shape for a button like:

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

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" >
    <gradient android:startColor="#DD000000" android:endColor="#DD2d2d2d"  android:angle="90"></gradient>
    <corners android:radius="15dip"></corners>

</shape>

Now I want to use a selector like:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/active"
      android:state_pressed="true" />
<item android:drawable="@drawable/passive"/>

for this Button as well. Is it possible ...???

Answer

Hanry picture Hanry · Sep 30, 2011

use this way:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:state_pressed="true" >
       <shape>.......</shape>
   </item>
   ..........
   ..........
</selector>