以编程方式设置AppCompatCheckBox的背景着色

时间:2016-05-13 13:14:00

标签: android android-support-library android-appcompat

我想在运行时为CheckBox着色。它不能使用主题静态完成。我可以主题文字&复选框drawable没有任何问题。

我希望这可行:

int[][] states = new int[][] {
            new int[] { android.R.attr.state_enabled}, // enabled
            new int[] {-android.R.attr.state_enabled}, // disabled
            new int[] {-android.R.attr.state_checked}, // unchecked
            new int[] { android.R.attr.state_pressed}  // pressed
    };
    int[] backgroundColors = new int[] {
            backgroundColor,
            backgroundColor,
            backgroundColor,
            backgroundColor
    };
    ColorStateList backgroundColorStateList = new ColorStateList(getStates(), backgroundColors);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        checkbox.setBackgroundTintList(backgroundColorStateList);
    }

但即使在Marshmallow设备上,这对背景也没有任何作用。

动态地对Android中的任何事物进行动态制作都非常可怕且非常耗费时间。为什么上面的代码不起作用,setSupportBackgroundTintList()?

在哪里

目前我正在使用它,但它消除了涟漪和阴影:

    checkbox.setBackgroundColor(backgroundColor);

即使使用AppCompat,是否真的没办法为Checkbox背景着色?

0 个答案:

没有答案