RightRadioButton.java
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.sw.laryngoscope.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.CompoundButton;
import com.sw.laryngoscope.R;
public class RightRadioButton extends androidx.appcompat.widget.AppCompatRadioButton
implements CompoundButton.OnCheckedChangeListener {
public RightRadioButton(Context context) {
this(context, null);
setOnCheckedChangeListener(this);
setCompoundDrawables(null, null, null, null);
}
public RightRadioButton(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.radioButtonStyle);
setOnCheckedChangeListener(this);
setCompoundDrawables(null, null, null, null);
}
public RightRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOnCheckedChangeListener(this);
setCompoundDrawables(null, null, null, null);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if ( isChecked ) {
Drawable drawable = getResources().getDrawable(R.mipmap.img_enter);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
setCompoundDrawables(null, null, drawable, null);
} else {
setCompoundDrawables(null, null, null, null);
}
}
}