gpt4 book ai didi

android - 以编程方式更改 colorControlActivated 颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:07 30 4
gpt4 key购买 nike

我已经阅读了一些关于颜色的主题,但所有主题都必须通过 style.xml 进行设置。

现在我用它来确定颜色。

<style name="Color1SwitchStyle">
<item name="colorControlActivated">#0e8488</item>
</style>'

是否可以在不使用 XML(例如使用代码)的情况下更改 SwitchCompat/Checkbox 的颜色?

最佳答案

其实做起来并不难

例子:

int[][] states = new int[][] {
new int[] {-android.R.attr.state_checked},
new int[] {android.R.attr.state_checked},
};

int[] thumbColors = new int[] {
Color.BLACK,
Color.RED,
};

int[] trackColors = new int[] {
Color.GREEN,
Color.BLUE,
};

SwitchCompat switchCompat = (SwitchCompat) findViewById(R.id.switchControl);
AppCompatCheckBox checkBox = (AppCompatCheckBox) findViewById(R.id.checkbox);
checkBox.setSupportButtonTintList(new ColorStateList(states, thumbColors));
DrawableCompat.setTintList(DrawableCompat.wrap(switchCompat.getThumbDrawable()), new ColorStateList(states, thumbColors));
DrawableCompat.setTintList(DrawableCompat.wrap(switchCompat.getTrackDrawable()), new ColorStateList(states, trackColors));

关于android - 以编程方式更改 colorControlActivated 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32499691/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com