2020-05-13
首先洪唐,使用android.support.v7.widget.SwitchCompat
1亲桦、設(shè)置底部軌道顏色:app:trackTint
<android.support.v7.widget.SwitchCompat
android:id="@+id/Switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:checked="false"
android:padding="10dp"
android:textOff="開"
android:textOn="關(guān)"
app:trackTint="@color/gray_37" />
2、設(shè)置選中時(shí)的圓圈顏色:
(1)在styles.xml文件里定義一個(gè)style:
colorAccent就是圓圈顏色
<style name="GoldenAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<!-- <item name="colorPrimary">@color/colorPrimary</item>-->
<!-- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
<item name="colorAccent">@color/them_color_gold</item>
</style>
(2)配置文件里當(dāng)前Activity設(shè)置them:
<activity
...
android:theme="@style/GoldenAppTheme" />