我正在使用 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>