Android:SwitchCompat,填充和颜色问题

前端之家收集整理的这篇文章主要介绍了Android:SwitchCompat,填充和颜色问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@
我正在使用 android.support.v7.widget.SwitchCompat,我遇到了以下问题

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

我的代码

Styles.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"
    >

所以在上面的文字中,AllCaps不会使拇指上的文字全部大写.

切换填充无效

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

解决方法

确保您的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()方法控制拇指的字体和样式.

原文链接:https://www.f2er.com/android/315071.html

猜你在找的Android相关文章