ThemeButton.java 文件源码

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

项目:talk-android 作者:
public void setThemeBackground(int color, int colorPressed) {
    int radius = DensityUtil.dip2px(getContext(), 2);
    float[] radii = new float[]{radius, radius, radius, radius, radius, radius, radius, radius};

    StateListDrawable states = new StateListDrawable();

    RoundRectShape disableShape = new RoundRectShape(radii, null, null);
    ShapeDrawable disableDrawable = new ShapeDrawable(disableShape);
    disableDrawable.getPaint().setColor(getResources().getColor(R.color.material_grey_300));
    states.addState(new int[]{-android.R.attr.state_enabled}, disableDrawable);

    RoundRectShape pressedShape = new RoundRectShape(radii, null, null);
    ShapeDrawable pressedDrawable = new ShapeDrawable(pressedShape);
    pressedDrawable.getPaint().setColor(colorPressed);
    states.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable);

    RoundRectShape normalShape = new RoundRectShape(radii, null, null);
    ShapeDrawable normalDrawable = new ShapeDrawable(normalShape);
    normalDrawable.getPaint().setColor(color);
    states.addState(new int[]{-android.R.attr.state_pressed}, normalDrawable);

    setBackgroundDrawable(states);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号