繁体   English   中英

Android:在白色背景上跟踪switchcompat隐形

[英]Android: track invisible for switchcompat when on white background

我有一个背景为白色的活动,我添加了一个switchcompat,但是当开关未激活(关闭)时,该轨道是不可见的。 所有可见的都是拇指,因此对于用户来说,它根本不是一个开关。 当开关处于非活动位置时,如何使开关的轨迹可见?

                    <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"
                        />

这样做的方法是定义一个这样的自定义主题:

<style name="Custom.SwitchCompat.WhiteTrack" parent="Base.Widget.AppCompat.CompoundButton.Switch">
        <!-- Inactive track color(30% transparency) -->
        <item name="android:colorForeground">[some color]</item>
    </style>

然后在你的布局中定义主题,如下所示:

android:theme="@style/Custom.SwitchCompat.WhiteTrack"

etvoilà。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM