Using A Background Drawable Selector On Custom Button
I am extending 'Button' to create a custom button which I am adding extra functionality to -- and currently, the background drawable is not changing on touch. Here is some sample
Solution 1:
Pskink said in a comment in the question:
why in ctor(Contexr) you call super(Context, null) and in ctor(Context, AttributeSet) you use super(Context, AttributeSet, int)
And that's exactly what was wrong...
publicCustomButton(final Context context, final AttributeSet attrs) {
this(context, attrs, 0);
}
should be:
publicCustomButton(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
Solution 2:
// Try This.
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/b_gradient_pressed"android:state_pressed="true"></item><itemandroid:drawable="@drawable/b_gradient_pressed"android:state_focused="true"></item><itemandroid:drawable="@drawable/b_gradient"android:state_enabled="true"android:state_focused="false"android:state_pressed="false"></item><itemandroid:drawable="@drawable/b_gradient_pressed"android:state_enabled="false"></item></selector>
Post a Comment for "Using A Background Drawable Selector On Custom Button"