9

我正在使用 android.support.v7.widget.SwitchCompat 并且遇到以下问题

  • 我的包含 colorControlActivated 的样式不适用
  • 使用 Android 命名空间和 Res-Auto 切换填充无效
  • 如何将拇指文本设置为全部大写

我的代码

样式.xml

注意我试过没有父母和 Theme.AppCompat.Light.NoActionBar

<style name="ToggleSwitchStyle" parent="Theme.AppCompat">
    <item name="colorControlActivated">@color/emerald</item>
</style>

我的 SwitchCompat 在 XML 布局中定义

<android.support.v7.widget.SwitchCompat
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:padding="5dp"
    android:textOff="@string/no"
    android:textOn="@string/yes"
    app:showText="true"
    android:switchPadding="5dp"
    app:switchPadding="10dp"
    app:theme="@style/ToggleSwitchStyle"
    android:theme="@style/ToggleSwitchStyle"
    android:textAllCaps="true"
    app:thumbTextPadding="5dp"
    >

所以在上面的 textAllCaps 不会使拇指上的文本全部大写。

开关填充没有效果

使用 Res-Auto 或 Android 命名空间的主题对活动颜色没有影响。

但是,我可以通过更改材质主题的颜色重音来更改活动颜色

 <!-- Application theme. -->
    <style name="MaterialDesign" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/yellow</item>
    </style>
4

1 回答 1

1

确保您的 Styles.xml 位于 values-v21 文件夹中。我在 switchcompat 更改颜色时遇到了类似的问题。

这对我有用。将 styles.xml 保存在 values-v21 文件夹和 ColorAccent 中以更改开关的颜色。

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="colortoggle">
        <item name="colorAccent">@color/continue_button</item>
    </style>
</resources>

对于拇指问题: textAppearance 和相关的 setTypeface() 方法控制标签文本的字体和样式,而 switchTextAppearance 和相关的 seSwitchTypeface() 方法控制拇指的字体和样式。

于 2015-06-30T06:56:09.433 回答