我要创建它采用Android 4.0的应用程序。 我不知道是否有可能改变文本的文本颜色的开关。
I'm creating an application which uses Android 4.0. I'm wondering if it is possible to change the text color of the text in a switch.
我已经尝试设置文本的颜色,但它不能正常工作。
I've tried setting the text color, but it doesn't work.
任何想法?
在此先感谢!
您必须使用安卓switchTextAppearance
属性,如:
android:switchTextAppearance="@style/SwitchTextAppearance"
而在样式:
<style name="SwitchTextAppearance" parent="@android:style/TextAppearance.Holo.Small">
<item name="android:textColor">@color/my_switch_color</item>
</style>
您也可以做到这一点在code,还用上面的样式:
you can also do it in code, also using above styles:
mySwitch.setSwitchTextAppearance(getActivity(), R.style.SwitchTextAppearance);
......并以此为 setTextColor
和开关
- 这种颜色会如果你的 SwitchTextAppearance 风格不提供文字颜色
...and as for setTextColor
and Switch
- this color will be used if your SwitchTextAppearance
style doesn't provide a textColor
您可以检查它在开关
源$ C $ c。在 setSwitchTextAppearance
:
you can check it in Switch
source code in 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();
}
}
上一篇:我怎样才能得到一个ListView项的高度?高度、ListView
下一篇:CruiseControl的&QUOT;未使用的节点检测到的QUOT;添加的xmlns到项目节点时出错节点、检测到、项目、CruiseControl