我正在创建一个使用 Android 4.0 的应用程序。
我想知道是否可以更改开关中文本的文本颜色。
我尝试过设置文本颜色,但不起作用。
有任何想法吗?
提前致谢!
你必须使用android:switchTextAppearance
属性,例如:
android:switchTextAppearance="@style/SwitchTextAppearance"
以及样式:
<style name="SwitchTextAppearance" parent="@android:style/TextAppearance.Holo.Small">
<item name="android:textColor">@color/my_switch_color</item>
</style>
您也可以在代码中执行此操作,也使用上述样式:
mySwitch.setSwitchTextAppearance(getActivity(), R.style.SwitchTextAppearance);
...至于setTextColor
and Switch
- 如果您的SwitchTextAppearance
样式不提供textColor
你可以检查一下Switch
源代码在setSwitchTextAppearance
:
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();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)