Java Kotlin-如何动态更改SwitchCompat样式
我有一个Java Kotlin-如何动态更改SwitchCompat样式,java,android,kotlin,android-theme,switchcompat,Java,Android,Kotlin,Android Theme,Switchcompat,我有一个 <androidx.appcompat.widget.SwitchCompat android:id="@+id/switch_me" android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/some_text" android:
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_me"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/some_text"
android:textColor="@color/white"
android:theme="@style/SwitchTheme1" />
<style name="SwitchTheme1" parent="ThemeOverlay.AppCompat.Light">
<item name="colorControlActivated">@color/white</item>
<item name="trackTint">@color/colorPrimary1</item>
</style>
<style name="SwitchTheme2" parent="ThemeOverlay.AppCompat.Light">
<item name="colorControlActivated">@color/white</item>
<item name="trackTint">@color/colorPrimary2</item>
</style>
override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? {
val view = inflater.inflate(R.layout.fragment_settings, container, false)
if(some_condition == "my value"){
/*Set SwitchTheme1*/
}else{
/*Set SwitchTheme2*/
}
return view
}