【发布时间】:2018-04-12 15:27:51
【问题描述】:
我正在寻找仅将此颜色应用于所有开关。但默认情况下,它使用colorAccent 而不是这个主题进行切换。
设备:棉花糖。
布局:
<Switch
android:id="@+id/soundSwitch"
style="@style/SwitchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="@dimen/large_space"
android:layout_marginRight="@dimen/medium_space"
android:layout_marginTop="@dimen/large_space"
android:checked="true"
/>
样式-v21:
<style name="SwitchStyle" parent="Theme.AppCompat.Light">
<!-- active thumb & track color (30% transparency) -->
<item name="android:colorControlActivated">@color/switch_color</item>
<!-- inactive thumb color -->
<item name="colorSwitchThumbNormal">#f1f1f1</item>
<!-- inactive track color (30% transparency) -->
<item name="android:colorForeground">#42221f1f</item>
</style>
我做错了什么?
【问题讨论】:
-
如果你挣扎并失败了,你可能会通过覆盖 colorAccent
<item name="colorAccent">your color</item>
标签: android android-styles android-switch