我正在使用一个标准的开关控制与全息。轻主题在ICS应用程序。
我想改变切换按钮的高亮或状态颜色,从标准的浅蓝色到绿色。
这应该很容易,但我似乎不知道该怎么做。
我正在使用一个标准的开关控制与全息。轻主题在ICS应用程序。
我想改变切换按钮的高亮或状态颜色,从标准的浅蓝色到绿色。
这应该很容易,但我似乎不知道该怎么做。
当前回答
这招对我很管用——
1.values/styles.xml中的代码:
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
<item name="android:colorControlActivated">#148E13</item>
</style>
2.在布局文件的交换机中添加以下代码行-:
android:theme="@style/SwitchTheme"
其他回答
可能有点晚了,但是对于开关按钮,toogle按钮不是答案,你必须改变开关xml参数中的drawable:
android:thumb="your drawable here"
根据这里的一些答案的组合,这对我来说是有效的。
<Switch
android:trackTintMode="src_over"
android:thumbTint="@color/white"
android:trackTint="@color/shadow"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:thumbTint="@color/white"
app:trackTint="@drawable/checker_track"/>
在checker_track.xml中:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/lightish_blue" android:state_checked="true"/>
<item android:color="@color/hint" android:state_checked="false"/>
</selector>
在Android Lollipop和以上版本中,在你的主题样式中定义它:
<style name="BaseAppTheme" parent="Material.Theme">
...
<item name="android:colorControlActivated">@color/color_switch</item>
</style>
Android Studio 3.6解决方案:
yourSwitch.setTextColor(getResources().getColor(R.color.yourColor));
更改颜色XML文件定义值(yourColor)中的文本颜色。