Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Kotlin-如何动态更改SwitchCompat样式_Java_Android_Kotlin_Android Theme_Switchcompat - Fatal编程技术网

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
}