Solved. It was just a tiny horrible mistake.
But for anyone who has some problem like that I had this going to work very vell on android version 17 or above, for pre 17 I think the only way is to use separate layouts for RTL and LTR.
If you have to use android:supportsRTL="true"
in your manifest then:
1. If you want to support just RTL language, to prevent from changing the direction according to OS language:
Simply just add android:layoutDirection="rtl"
to parent of all your layouts (Also you can use theme in styles.xml
like this).
Or make an sub activity and extends all your activity from it, then put this code in it's onCreate:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Configuration configuration = getResources().getConfiguration();
configuration.setLayoutDirection(new Locale("fa"));
getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
}
But in my mind it's better to set the direction to rtl
in each layout because you can see how it's going to look without you run the app.
2. If you want to support both RTL and LTR languages, of course don't use android:layoutDirection="rtl/ltr"
in your layouts Because it's direction won't change any way even by code. Because it's going to fix it in the direction rtl
or ltr
. so you should use the second one. make an sub activity and extends all your activity from it, then put this code in it (It's just for example):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Configuration configuration = getResources().getConfiguration();
if (isSlectedLanguageRTL) {
configuration.setLayoutDirection(new Locale("fa"));
} else {
configuration.setLayoutDirection(Locale.ENGLISH);
}
getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
}
And at the end, sorry for my English :)