切换轨道颜色 [英] Switch Track Color
本文介绍了切换轨道颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用开关并更改其轨道颜色。所以在我看来没有壮观。
我的开关布局:
< Switch
android:id =@ + id / Switch1
android:layout_width =wrap_content
android:layout_height =wrap_content
android:layout_alignParentBottom =true
android:layout_centerHorizontal =true
android:track =@ color / gray
android:textOn =@ string / on
android:textOff =@ string / off
android:text =@ string / musiconoff/>
和我的颜色灰色:
< color name =grey>#666666< / color>
我的问题是开关显示为1像素开关。这只是一条小线。
我的错误在哪里?
if(isChecked) {
mSwtPrivacyView.getTrackDrawable()。setColorFilter(ContextCompat.getColor(this,R.color.switch_track_checked_true_color),PorterDuff.Mode.SRC_IN);
} else {
mSwtPrivacyView.getTrackDrawable()。setColorFilter(ContextCompat.getColor(this,R.color.switch_track_checked_false_color),PorterDuff.Mode.SRC_IN);
}
I want to use a Switch and change its Track Color. So in my opinion nothing spectacular.
My Switch layout:
<Switch
android:id="@+id/Switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:track="@color/gray"
android:textOn="@string/on"
android:textOff="@string/off"
android:text="@string/musiconoff" />
and my color "grey":
<color name="gray">#666666</color>
My Problem is that the Switch is shown as a 1-pixel Switch. It's just a small line. If I delete the "color"-line, the Switch is correct (without grey of course).
Where is my fault?
解决方案
Nothing worked for me except this
if (isChecked) {
mSwtPrivacyView.getTrackDrawable().setColorFilter(ContextCompat.getColor(this, R.color.switch_track_checked_true_color), PorterDuff.Mode.SRC_IN);
} else {
mSwtPrivacyView.getTrackDrawable().setColorFilter(ContextCompat.getColor(this, R.color.switch_track_checked_false_color), PorterDuff.Mode.SRC_IN);
}
这篇关于切换轨道颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文