ResUtil.java 文件源码

java
阅读 35 收藏 0 点赞 0 评论 0

项目:RLibrary 作者:
public static Drawable generateRoundDrawable(float radiiL, float radiiR, int pressColor, int defaultColor) {
    //外环的圆角矩形
    float[] outRadii = new float[]{radiiL, radiiL, radiiR, radiiR, radiiR, radiiR, radiiL, radiiL};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个

    //与内环的距离
    RectF inset = new RectF(0, 0, 0, 0);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, inset, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, null);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号