【发布时间】:2017-01-24 12:31:07
【问题描述】:
我的问题可能最好以视觉方式提出 -- 我想要一个 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"/>
谢谢!
【问题讨论】:
-
如果您禁用该自定义色调,您的曲目会返回吗?
-
您究竟是如何“应用自定义色调”的?你不是只用你主题的
colorControlActivated吗? -
我在我的问题中添加了更多详细信息,准确描述了我如何在此活动中进行颜色/主题自定义。 LMK 如果我可以或应该提供更多细节。谢谢!
标签: android switchcompat