动态改变shape的背景色

2019-01-04  本文已影响0人  Thor_果冻
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);
上一篇 下一篇

猜你喜欢

热点阅读