kimi
2021-02-18 749a5510a9f014446a3cd6ba57b3cb0cc8148dc1
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
package com.mylhyl.circledialog.res.drawable;
 
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
 
/**
 * Created by hupei on 2017/3/30.
 */
 
public class CircleDrawableSelector extends StateListDrawable {
 
    public CircleDrawableSelector(int backgroundColor, int backgroundColorPress) {
        this(backgroundColor, backgroundColorPress, 0, 0, 0, 0);
    }
 
    public CircleDrawableSelector(int backgroundColor, int backgroundColorPress, int leftTopRadius,
                                  int rightTopRadius, int rightBottomRadius, int leftBottomRadius) {
        //按下
        ShapeDrawable drawablePress = new ShapeDrawable(
                DrawableHelper.getRoundRectShape(leftTopRadius, rightTopRadius, rightBottomRadius, leftBottomRadius)
        );
        drawablePress.getPaint().setColor(backgroundColorPress);
        //默认
        ShapeDrawable defaultDrawable = new ShapeDrawable(
                DrawableHelper.getRoundRectShape(leftTopRadius, rightTopRadius, rightBottomRadius, leftBottomRadius)
        );
        defaultDrawable.getPaint().setColor(backgroundColor);
 
        addState(new int[]{android.R.attr.state_pressed}, drawablePress);
        addState(new int[]{-android.R.attr.state_pressed}, defaultDrawable);
    }
}