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

时间:2015-09-28 00:05:53

标签: java android user-interface switch-statement

我有一个背景为白色的活动,我添加了一个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"
                        />

1 个答案:

答案 0 :(得分:3)

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

<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à。

相关问题