A Farmanbar
A Farmanbar

Reputation: 4788

Device's default layout direction changes application's default layout direction when device language is changed

Recently i received reports from users about application layout direction disrupted and isn't displayed correct.

I made all direction ltr in the style.xml but some users change phone language.as a result, Device default layout direction changes and cause application direction reverse.(but i don't want)

ltr changes to rtl

rtl changes to ltr

my assumptions were that if i set static layout direction in style.xml layout never changes its direction but it didn't work and direction is changed.what i have to do?how can i prevent layout direction change?

Upvotes: 0

Views: 928

Answers (2)

Pavlo Ostasha
Pavlo Ostasha

Reputation: 16699

Here is how you can force LTR in your activities.

<item name="android:layoutDirection">ltr</item>

For example:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:layoutDirection">ltr</item>
</style>

You can also use it in layouts directly and combine different directions on a single view.

android:layoutDirection="rtl"

For example:

<LinearLayout android:id="@+id/layout_linearlayout_rtl"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layoutDirection="rtl">

        <LinearLayout android:id="@+id/layout_linearlayout_rtl_child_1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layoutDirection="ltr" />

        <LinearLayout android:id="@+id/layout_linearlayout_rtl_child_2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layoutDirection="rtl" />

        <LinearLayout android:id="@+id/layout_linearlayout_rtl_child_3"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layoutDirection="inherit" />

        <LinearLayout android:id="@+id/layout_linearlayout_rtl_child_4"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layoutDirection="locale" />

</LinearLayout>

It can be used since API 17.

Hope it helps

Upvotes: 3

Jignesh Mayani
Jignesh Mayani

Reputation: 7193

Try this

 android:supportsRtl="false"

Set this in manifest.xml inside <application> Tag

Upvotes: 0

Related Questions