【问题标题】:SwitchCompat RTL supportSwitchCompat RTL 支持
【发布时间】:2020-10-26 13:31:12
【问题描述】:

似乎track 属性的选择器文件不适用于 RTL。

LTR trackthumb

RTL trackthumb。此处thumb 已正确更改,但track 图像仍保持不变,因为它应该在右侧显示地图图标。

<androidx.appcompat.widget.SwitchCompat
        android:background="@drawable/selector_switch_track"
        android:elevation="6dp"
        android:outlineProvider="background"
        android:thumb="@drawable/selector_switch_thumb"
        app:track="@drawable/selector_switch_track" />

selector_switch_track.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true">
    <item android:state_checked="true">
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="@color/global_white" />
                    <corners android:radius="@dimen/margin_100dp" />
                </shape>
            </item>
            <item android:drawable="@drawable/layer_switch_thumb_map_off" android:gravity="start" android:right="@dimen/margin_56dp" />
            <item android:drawable="@drawable/layer_switch_thumb_list_off" android:gravity="end" android:left="@dimen/margin_56dp" />
        </layer-list>
    </item>
    <item android:state_checked="false">
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="@color/global_white" />
                    <corners android:radius="@dimen/margin_100dp" />
                </shape>
            </item>
            <item android:drawable="@drawable/layer_switch_thumb_map_off" android:gravity="start" android:right="@dimen/margin_56dp" />
            <item android:drawable="@drawable/layer_switch_thumb_list_off" android:gravity="end" android:left="@dimen/margin_56dp" />
        </layer-list>
    </item>
</selector>

【问题讨论】:

    标签: android switchcompat


    【解决方案1】:

    我通过为 RTL 创建单独的 res dir drawable-ldrtl 并将相同的 selector 文件放在那里但具有切换的开始/结束可绘制对象来解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      相关资源
      最近更新 更多