你必须使用android:switchTextAppearance属性,例如:
android:switchTextAppearance="@style/SwitchTextAppearance"
和风格:
@color/my_switch_color
你也可以在代码中执行,也可以使用以上样式:
mySwitch.setSwitchTextAppearance(getActivity(), R.style.SwitchTextAppearance);
…以及对于setTextColor和Switch – 如果您的SwitchTextAppearance样式不提供textColor,则将使用此颜色
您可以在setSwitchTextApp中的Switch源代码中查看它:
ColorStateList colors;
int ts;
colors = appearance.getColorStateList(com.android.internal.R.styleable.
TextAppearance_textColor);
if (colors != null) {
mTextColors = colors;
} else {
// If no color set in TextAppearance, default to the view's textColor
mTextColors = getTextColors();
}
ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.
TextAppearance_textSize, 0);
if (ts != 0) {
if (ts != mTextPaint.getTextSize()) {
mTextPaint.setTextSize(ts);
requestLayout();
}
}