首页 > 解决方案 > 应用样式后,SwitchMaterial 不会更改 textStyle

问题描述

代码:

分段:

        <com.google.android.material.switchmaterial.SwitchMaterial
            android:id="@+id/changeDateFormatSwitch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:text="@string/timeFormat"
            android:theme="@style/switchText"
            app:layout_constraintEnd_toEndOf="@+id/timePicker"
            app:layout_constraintStart_toStartOf="@+id/timePicker"
            app:layout_constraintTop_toBottomOf="@+id/timePicker"
            app:switchTextAppearance="@style/switchText" />

主题:

(如您所见,我尝试了很多东西……但没有一个奏效……但是?)

  <style name="switchText">
        <item name="android:textColor">@color/gold</item>
        <item name="android:textColorPrimary">@color/gold</item>
        <item name="android:editTextColor">@color/gold</item>
        <item name="colorControlNormal">@color/gold</item>
        <item name="colorControlActivated">@color/gold</item>
    </style>

任何想法我应该改变什么来改变:

在此处输入图像描述

文字颜色?

提前致谢 :)

标签: androidxmlkotlinandroid-stylesmaterial-components-android

解决方案


您可以使用:

<com.google.android.material.switchmaterial.SwitchMaterial
    style="@style/Widget.App.CompoundButton.Switch"
    ../>

和:

<style name="Widget.App.CompoundButton.Switch" parent="@style/Widget.MaterialComponents.CompoundButton.Switch">
    <item name="android:textColor">@color/...</item>
</style>

在此处输入图像描述


推荐阅读