[英]Android: track invisible for switchcompat when on white background
I have an activity whose background is white, and I added a switchcompat, however when the switch is not active (off) the track is invisible. 我有一个背景为白色的活动,我添加了一个switchcompat,但是当开关未激活(关闭)时,该轨道是不可见的。 All that is visible is the thumb so it isn't obvious to the user that it's a switch at all. 所有可见的都是拇指,因此对于用户来说,它根本不是一个开关。 How can I make the switch's track visible when the switch is in the de-active position? 当开关处于非活动位置时,如何使开关的轨迹可见?
<android.support.v7.widget.SwitchCompat
android:id="@+id/someswitchname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
The way to do this is to define a custom theme like this: 这样做的方法是定义一个这样的自定义主题:
<style name="Custom.SwitchCompat.WhiteTrack" parent="Base.Widget.AppCompat.CompoundButton.Switch">
<!-- Inactive track color(30% transparency) -->
<item name="android:colorForeground">[some color]</item>
</style>
then define the theme in your layout like this: 然后在你的布局中定义主题,如下所示:
android:theme="@style/Custom.SwitchCompat.WhiteTrack"
et voilà. etvoilà。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.