I made a custom checkbox xml as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
<item android:drawable="@drawable/checkbox_selected_glow" android:state_focused="true" android:state_pressed="true" android:state_checked="true"/>
<item android:drawable="@drawable/checkbox_selected_glow" android:state_focused="false" android:state_pressed="true" android:state_checked="true"/>
<item android:drawable="@drawable/checkbox_selected" android:state_focused="false" android:state_pressed="false" android:state_checked="true"/>
<item android:drawable="@drawable/checkbox_deselected_glow" android:state_focused="true" android:state_pressed="true" android:state_checked="false"/>
<item android:drawable="@drawable/checkbox_deselected_glow" android:state_focused="false" android:state_pressed="true" android:state_checked="false"/>
<item android:drawable="@drawable/checkbox_deselected" android:state_focused="false" android:state_pressed="false" android:state_checked="false"/>
</selector>
And the implementation in a layout:
<CheckBox
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:paddingRight="10dp"
android:button="@null"
android:background="@drawable/custom_checkbox"/>
It works well and reacts to the user touching it passing to the pressed state when the user touches it and to the selected/deselected state whenever the user releases the touch.
This CheckBox is associated with some text in a TextView and both are contained in a LinnearLayout.
I want the pressed state of the CheckBox to be activated whenever the user presses anywhere on the LinnearLayout.
Is there an xml only way to do this?
If not, what methods do I have to override on the LinnearLayout to programatically make the CheckBox react to touches on any part of the LinnearLayout?
Aucun commentaire:
Enregistrer un commentaire