我需要更改SwitchCompat的轨迹颜色。我试过this,但它对我不起作用。这是我的XML文件的代码
<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" />这是我的style.xml文件
<style name="switchStyle">
<item name="colorControlActivated">@color/red</item>
<item name="android:colorForeground">@color/gray</item>
</style>看起来是什么问题?
此外,我不能更改活动的颜色或基础应用程序的颜色。我必须为这个单独的视图更改颜色。
发布于 2016-02-05 12:51:23
试试这段代码。
<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>发布于 2022-01-31 08:01:58
更好的方法是,
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#15A215" android:state_checked="true"/>
<item android:color="#BAC7CB" android:state_checked="false"/>
</selector><style name="SwitchStyle">
<item name="thumbTint">#ffffff</item>
<item name="trackTint">@color/switch_track_color</item>
</style>https://stackoverflow.com/questions/32327920
复制相似问题