I asked this question before (here) but nobody answered so I ask It a little bit simpler.
The problem is when I change the layout direction to RTL
(in
xml file : android:layoutDirection="rtl"
or programmatically :
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
getWindows().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
doesn't matter) the navigation icon remain LTR
How can I fix this issue?
To be more specific the arrow should point at right!
This bug happens on Android 4.2 (API 17) only, when using the AppCompat support library version 24 or above.
In previous support library versions like:
... It was handled automatically, because this older library contained the drawable images of the arrow facing both left and right:
drawable
anddrawable-ldrtl
, ...)You can see these images in Android Studio -> View -> Tool Windows -> Project -> Select "Project" in the drop-down menu -> appcompat-v7-23.0.1 -> res -> drawable -> ...
In newer versions of AppCompat, such as
The arrow image now only exists as a single vector drawable pointing towards the left:
And Android 4.2 does not seem to be able to mirror it in the opposite direction for RTL mode. And the library does not contain a fallback image.
So a potential way to fix it, without creating your own custom image, is to use the older AppCompat support library version 23 or below. But this may not be compatible with newer tools/libraries.
There is property called auto mirror which itself rotate the icon on the basis of locale .
If you are using Toolbar and added the icon as navigation icon , then use the below line to rotate the icon
If you are using image view , then just add a style to the image view to rotate icon . Do create a different style for arabic . In your style file add the following code :
Go for the vector drawables as they default have this auto mirror property .
The problem is because the arrow is not following the RTL situation of the app
I had the same problem and I ended up creating a custom toolbar
use a NoActionBar theme and create an empty with only android.support.v7.widget.Toolbar in it
then include it in all activities needing a toolbar
and in activity do this
the custom one will follow the RTL direction of the app
I had same problem with Animation, and I resolved it! As I noticed, it is bug for versions below KitKat(and for sure above 4.2, include). What you need to do, as was said here, it is rotate for 180 in right place.
You have to create your own ActionBarDrawerToggle based on the given code by Google. Inside you will find class DrawerArrowDrawableToggle - it is custom Drawable, that draw Arrow/Humberger "animation". Like before you have to create your own class, based on the code of DrawerArrowDrawableToggle, and inside you will find variable "flipToPointRight" and take care that it will be "RIGHT" and you have take care that rotation won't work on versions >= Kitkat, otherwise will have the problem there. It is all.
I just added a
drawable
icon that rotated 180 degree and set the icon inonCreate()
but the problem is we should do this in every activity that It's layout isRTL
. So if our application supports both directions we should check if layout direction isRTL
then change the up indicator:u can use :
and Add RTL arrow to drawable