Skip to content Skip to sidebar Skip to footer

Android - Wrong Layout Direction When Switching RTL Vs LTR Many Times

When I switch my app language between EN and AR (during runtime) the views behave correctly by moving from the LTR to the RTL but when I start stressing the app by switching langua

Solution 1:

I can't imagine a user who will switch language many times and then returning to app on every change :)

But, anyway, if Android is not able to recreate your activities correctly you always can do it manually by setting "android:configChanges" in AndroidManifest.xml for your activities and then listening for onConfigurationChanged(Configuration newConfig) method in such activities:

In AndroidManifest.xml:

<activity android:name=".MyActivity"
          android:configChanges="layoutDirection">

In Activity for which you set android:configChanges:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (newConfig.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        // change directions for you views to RTL
    } else {
        // change directions for you views to LTR
    }
}

Solution 2:

make sure that supportsRtl="true"

<application
    android:supportsRtl="true"
    android:name=".App"
    android:icon="@drawable/news"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
</application>

Post a Comment for "Android - Wrong Layout Direction When Switching RTL Vs LTR Many Times"