0

Seems like selector file for track attribute is not working properly for RTL.

LTR track and thumb.

enter image description here enter image description here

RTL track and thumb. Here thumb is changed properly, but track images are still unchanged as it should display map icon on the right.

enter image description here

<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>
P.Juni
  • 2,365
  • 14
  • 26

1 Answers1

0

I solved this issue by creating seperate res dir drawable-ldrtl for RTL and put there same selector file but with switched start/end drawables.

P.Juni
  • 2,365
  • 14
  • 26