其實,這並不難。
例子:
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));
你對這個樣子? http://stackoverflow.com/a/27879897 – Sree
是的,但我不知道如何通過代碼訪問ColorStateList。 –
http://stackoverflow.com/a/17788095 – Sree