我的问题可能最好从视觉上提出——我希望SwitchCompat开关看起来像他们在 Android 设置应用程序中所做的那样:
这是关闭的:
这是在:
但由于某种原因,我的SwitchCompat开关在关闭时看起来像这样:
没有灰色的“轨道”延伸到右侧。但是,当打开时,它看起来像预期的那样:
如您所见,我已将自定义色调应用于我的应用程序。我的自定义色调应用如下:
<activity
android:name=".editor.MySettingsEditor"
android:theme="@style/Theme.MyCustomTheme" />
然后,在styles.xml 中:
<style name="Theme.MyCustomTheme" parent="Theme.AppCompat">
<item name="colorAccent">@color/myColorAccent</item>
<item name="colorPrimary">@color/myColorPrimary</item>
<item name="colorPrimaryDark">@color/myColorPrimaryDark</item>
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>
为确保不是我的自定义样式导致此问题,我通过以下操作将其删除:
<activity
android:name=".editor.MySettingsEditor"
android:theme="@style/Theme.AppCompat" />
但是,“关闭”轨道仍然没有显示,尽管色调现在变成了 Android 默认的蓝绿色。
为什么我的SwitchCompat开关在关闭状态时会丢失灰色轨迹?
描述 SwitchCompat 的 XML 非常简单:
<android.support.v7.widget.SwitchCompat
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
谢谢!





