I need to change SwitchCompat's track color. I've tried this, but it didn't worked for me. This is code of my XML file
<android.support.v7.widget.SwitchCompat
android:id="@+id/sc_push"
style="@style/switchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:theme="@style/switchStyle"
app:theme="@style/switchStyle" />
and this is my style.xml file
<style name="switchStyle">
<item name="colorControlActivated">@color/red</item>
<item name="android:colorForeground">@color/gray</item>
</style>
What seems the problem?
In addition, I can't change the activity's color or base application's color. I have to change color for this single view.
Try this code.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<!-- Active thumb color & Active track color(30% transparency) -->
<item name="colorControlActivated">@color/theme</item>
<!-- Inactive thumb color -->
<item name="colorSwitchThumbNormal">@color/grey300</item>
<!-- Inactive track color(30% transparency) -->
<item name="android:colorForeground">@color/grey600</item>
...
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With