Reputation: 825
In my project I have a CheckBox and I am trying to add a Custom image for checked and unchecked state but the images are not showing properly for xhdpi screen.Kindly help
I am posting the xml and screen shots
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/ic_uncheck" />
<item android:state_checked="true" android:drawable="@drawable/ic_check" />
<item android:drawable="@drawable/ic_uncheck" /> <!-- default -->
</selector>
<CheckBox
android:id="@+id/chkVibrate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:button="@drawable/checkbox"
android:text="CheckBox Text"
android:textColor="@color/white" />
click here for the xhdpi image
Upvotes: 2
Views: 2309
Reputation: 4499
You should use your custom xml file for button property
<CheckBox
android:id="@+id/chkVibrate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:button="@drawable/custom_checkbox"
android:text="CheckBox Text"
android:textColor="@color/white" />
you can create a custom file in this way too if you want to set different image in different focused states.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/ic_check"
android:state_focused="false">
</item>
<item android:state_checked="true"
android:drawable="@drawable/ic_check"
android:state_focused="true">
</item>
<item android:state_checked="false"
android:drawable="@drawable/ic_uncheck"
android:state_focused="false">
</item>
<item android:state_checked="false"
android:drawable="@drawable/ic_uncheck"
android:state_focused="true">
</item>
</selector>
Upvotes: 1