Issue
I am trying to create custom Check Box button image. After some research, I came across this code sample:
<CheckBox android:id="@+id/chkFav" android:layout_width="wrap_content"
android:layout_marginRight="0dp" android:button="@drawable/checkbox"
android:layout_height="wrap_content" android:clickable="true"/>
My query is how to actually implement android:button in code.
Solution
setButtonDrawable(Drawable d) is the way to go for. Make sure it is state-list drawable to respond to user interaction.
Step By step instruction
- Have at least 2 images. (one for checked state and another for normal state)
- Create xml drawable. http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
- Use setButtonDrawable(R.drawable.your_xml_drawable).
**Notes-- there are many ways to achieve. This is just one simple way to do it.
Answered By - PH7
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.