0

this is my code which changebutton size to rounded but not change color how do i do? define colors in another file colors.xml in value folder how i doboth in one code change button shape to rectangle also change color when click???

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

 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
   <shape 
   android:shape="rectangle" android:padding="10dp">
 <!-- you can use any color you want I used here gray color-->
 <solid android:color="#E0E0E0"/> 
 <corners
 android:bottomRightRadius="10dp"
 android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
  android:topRightRadius="10dp"/>
 </shape>
 </item>
 <item android:state_focused="true" android:state_pressed="true" 
        android:drawable="@drawable/blue_color" /> 
  <item android:state_focused="false" android:state_pressed="true" 
        android:drawable="@drawable/red_color" /> 
  <item android:drawable="@drawable/green_color" />

 </selector>





  <!-- colors.xml --->
  <?xml version="1.0" encoding="utf-8"?>
 <resources>
<drawable name="red_color">#ff0000</drawable>
 <drawable name="blue_color">#0000ff</drawable>
<drawable name="green_color">#00ff00</drawable>
 </resources>
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Hayya ANAM
  • 575
  • 2
  • 14
  • 38
  • 1
    What exactly do you want to achieve? So far your code should be working like this - your shape is always rounded, but it changes color only if it's pressed – Piotr Chojnacki Sep 26 '12 at 07:54
  • check out the link http://stackoverflow.com/a/12446491/1278196 – moDev Sep 26 '12 at 08:01

1 Answers1

0

You can use FrameLayout. set behind background in FrameLayout and set front background in LinearLayout. pay attention the LinearLayout background placed on top of FrameLayout background.

Try This Code!

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bgBehind">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bgFront">

    </LinearLayout>
</FrameLayout>
D.L.MAN
  • 990
  • 12
  • 18