スイッチボタンの色変更 kotlin
スイッチの色変更
https://github.com/zcweng/SwitchButton
上記のGithubを使用したボタンの色の変更です。
自分で作らないと、細かい仕様変更に対応するのも大変ですよね。
styles.xmlを使用しているので、そこでもいじります。
[values/styles.xml]
<style name="CustomSwitch" parent="Theme.AppCompat.Light">
<item name="sb_checked_color">@color/color_white</item>
</style>
[fragment_buttom.xml]
<com.suke.widget.SwitchButton
android:id="@+id/sbtn_notify"
android:theme="@style/CustomSwitch"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_marginEnd="10dp"
app:sb_checked_color= "@color/color_black"
/>
正直、Gitに書いてあるソースを書いても何の色も変更されないし、普通のSwitchButtonの色の変更コードを書いてもびくともしません。
まだ間に合うのであれば他のものを参考にするか、自分で1から作るのをお勧めします。
自分のただの力量不足が原因ではありますが、調べてここにたどり着くということはそういうことでは無いかとも思います。
参考
https://github.com/zcweng/SwitchButton
[.xml]
<com.suke.widget.SwitchButton
android:id="@+id/btn_notify"
android:theme="@style/CustomSwitch"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_marginEnd="10dp"
app:sb_checked="true"
app:sb_show_indicator="false"
/>
[styles.xml]
<style name="CustomSwitch" parent="Theme.AppCompat.Light">
<item name="sb_checked_color">@color/color_white</item>
</style>