【问题标题】:SwitchMaterial doesn't change textStyle after applying style应用样式后,SwitchMaterial 不会更改 textStyle
【发布时间】:2021-04-11 21:10:34
【问题描述】:

代码:

片段:

        <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>

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

文字颜色?

提前致谢:)

【问题讨论】:

    标签: android xml kotlin android-styles material-components-android


    【解决方案1】:

    你可以使用:

    <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>
    

    【讨论】:

      猜你喜欢
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      • 2014-06-08
      • 1970-01-01
      相关资源
      最近更新 更多