I use a xml file to color my button. In the xml a have this code to define the color of my button when it's clicked.
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="@color/mainRaddoppiaButtonBackgroundEnd"
android:endColor="@color/mainRaddoppiaButtonBackgroundStart"
android:angle="270" />
<stroke
android:width="0dp"
android:color="@color/mainRaddoppiaButtonBackgroundStart" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:startColor="@color/mainRaddoppiaButtonBackgroundEnd"
android:endColor="@color/mainRaddoppiaButtonBackgroundStart"
android:angle="270" />
<stroke
android:width="0dp"
android:color="@color/mainRaddoppiaButtonBackgroundStart" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="@color/mainRaddoppiaButtonBackgroundStart"
android:endColor="@color/mainRaddoppiaButtonBackgroundEnd"
android:angle="270" />
<stroke
android:width="0dp"
android:color="@color/mainRaddoppiaButtonBackgroundStart" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
Is it possibile from java to keep my button pressed and color it with "state_pressed" values set in my xml file?
Someting like:
public void onClick(View button) {
button.seLayout(R.xml.xmlFileName.state_pressed)
}
Of course this code has no sense, i just made it up to let you understand what i want to do