3

I have a state list like this:

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

</selector>

And a shape like this (for rounding my button):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
 </shape>

My question is how do I apply both of them? If i set the backgroundResource to the color list, then I get the color, but then I cant use it for the shape. I tried using backgroundResource for the shape and backgroundColor for the color, but that didn't work.

LuxuryMode
  • 33,401
  • 34
  • 117
  • 188

2 Answers2

2
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true"
        android:drawable="@color/dark_green" >
        <shape android:shape="rectangle">
           <corners android:bottomRightRadius="7dp" 
                    android:bottomLeftRadius="7dp" 
                    android:topLeftRadius="7dp" 
                    android:topRightRadius="7dp"/>
 </shape>
    <item/>
    <item android:drawable="@color/bright_green" />
</selector>

I have done same of things like your.but,it doesn't work,when you use your dradwalbe. If you use like this(use solid to filing button not use drawable,can drow Rounded Button), it can be work.

<?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="#FFEC7600" />
         <corners
                        android:topLeftRadius="5dip"
                android:topRightRadius="5dip"
                android:bottomLeftRadius="5dip"
                android:bottomRightRadius="5dip" />
      </shape>
   </item>
oldfox3721
  • 101
  • 1
  • 1
  • 9
1

Have you tried to bundle them in an LayerDrawable XML definition?
Something like that.

Community
  • 1
  • 1
Knickedi
  • 8,742
  • 3
  • 43
  • 45