直播帶貨app原始碼,android Switch 修改顏色
阿新 • • 發佈:2020-12-24
技術標籤:技術類androidvuejavascriptappjava
直播帶貨app原始碼,android Switch 修改顏色的相關程式碼
設定switch顏色的四個屬性:
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:trackTint="#aaaaaa"
app:trackTintMode="multiply"
app:thumbTint="@color/colorPrimary"
app:thumbTintMode="multiply" />
控制滑塊顏色
app:thumbTint="……"
app:thumbTintMode="……"
其中thumbTint設定滑塊的資源,thumbTimtMode設定滑塊的染色模式
同理,滑道顏色也有兩個屬性,分別設定滑道資源和染色模式
app:trackTint="……"
app:trackTintMode="……"
Switch是Checkable的子類,有check屬性,同樣可以分別設定開關狀態的顏色
以設定滑塊顏色為例,在res包下新建color包,然後新建檔案:switch_thumb_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#4CAF50" android:state_checked ="false"/>
<item android:color="#FFC107" android:state_checked="true"/>
</selector>
設定滑塊資源
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:thumbTint="@color/switch_thumb_color"
app:thumbTintMode="multiply"
android:checked="true"/>
以上就是直播帶貨app原始碼,android Switch 修改顏色的相關程式碼, 更多內容歡迎關注之後的文章