如何解决SwitchCompat RTL支持
LTR track
和thumb
。
RTL track
和thumb
。 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>
解决方法
我通过为RTL创建单独的res dir drawable-ldrtl
并放置相同的selector
文件,但切换了开始/结束可绘制对象的方式解决了这个问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。