美文网首页
动态改变shape的背景色

动态改变shape的背景色

作者: Thor_果冻 | 来源:发表于2019-01-04 14:28 被阅读0次
GradientDrawable background = (GradientDrawable) viewHolder.color_tv.getBackground();
            //随机设置小圆点设置颜色
            Random random = new Random();
            int ranColor = 0xff000000 | random.nextInt(0x00ffffff);
            background.setColor(ranColor);
GradientDrawable shape = new GradientDrawable();
        int type = SettingXml.getShape(mInstance, DEFAULT_SHAPE);
        //设置形状
        if (type == SettingShapeActivity.CIRCLE) {
            shape.setShape(GradientDrawable.OVAL);
        } else if (type == SettingShapeActivity.RECTANGLE) {
            shape.setShape(GradientDrawable.RECTANGLE);
        }
        //设置颜色
        shape.setColor(SettingXml.getColor(mInstance, DEFAULT_COLOR));
        //设置大小
        shape.setSize(SettingXml.getSizeWidth(mInstance, DEFAULT_SIZE_W), SettingXml.getSizeHeight(mInstance, DEFAULT_SIZE_H));
        mFloatView.setBackground(shape);

相关文章

网友评论

      本文标题:动态改变shape的背景色

      本文链接:https://www.haomeiwen.com/subject/bpdplqtx.html