Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Button in XML

Tags:

android

xml

I made this XML file to customize a button

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

<corners android:radius="10dip" />

<gradient
    android:angle="90"
    android:centerColor="#0043E1"
    android:centerY="0.4"
    android:endColor="#6495ED"
    android:startColor="#6495ED"
    android:type="linear" />

</shape>

What should I add to make the state focus and pressed please? A gradient color for the state pressed, and another for the state focused?


1 Answers

You need to write the selector for the button

<?xml version="1.0" encoding="utf-8"?>
  <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_normal_color" android:state_focused="true"></item>
    <item android:drawable="@drawable/button_focus_color" android:state_pressed="true">/item>
    <item android:drawable="@drawable/button_normal_color"></item>
  </selector>

set this xml to the button back ground

like image 145
Jagadesh Seeram Avatar answered Sep 11 '26 00:09

Jagadesh Seeram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!