0

I need to change the background color of a button using shapes.

`

<?xml version="1.0" encoding="utf-8"?/>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_active="true">
            <shape android:shape="rectangle">
                <solid android:color="@color/blue3"/>
                <stroke android:color="@color/white1" android:width="2dp" />
                <corners android:radius="8dp" />
            </shape>
        </item>
    </selector>

`

I am trying to set blue3 color using solid but it's not appearing in view. Please make me correct if i am trying to do it incorrect way.

Shravan Jain
  • 720
  • 1
  • 11
  • 32

2 Answers2

1

Use this file in drawable

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

<item>
   <layer-list >

        <item>
            <shape>
                <solid android:color="#d4d4d4"></solid>
                <corners android:radius="2dp"></corners>
            </shape>
        </item>

       <item android:right="2dp" android:bottom="2dp" android:left="1dp" android:top="1dp">
        <shape>
               <solid android:color="#ff0000"></solid>
               <corners android:radius="2dp"></corners>
           </shape>
       </item>
   </layer-list>
</item>

and set Button background from drawable Hope this will help!

Akp
  • 259
  • 1
  • 9
-1

Here is the solution of this question.

`

<?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="@color/blue3" />
        <corners android:radius="8dp" />
    </shape>
</item>
</layer-list>

`

Shravan Jain
  • 720
  • 1
  • 11
  • 32