Search code examples
androidright-to-left

RTL support on ImageButton with autoMirror for src drawable


When creating an ImageButton with android:background="?android:attr/selectableItemBackground" and android:src="@drawable/ic_action_send", adding android:autoMirror="true" does not have any descernable affect. Is there any way to easily support Right-To-Left (RTL) image mirroring on ImageButtons?


Solution

  • Make an XML drawable and set android:autoMirrored="true". This value is ignored before API 19.

    res/drawable/icon_auto_mirrored.xml

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@drawable/icon"
            android:autoMirrored="true"/>
    

    Now use android:src="@drawable/icon_auto_mirrored in your layout.