4

In my application I started to set the UI to meet Material Design use the Toolbar.

I want to add the back arrow on the action bar. It looks ok but somehow, when I change my phone locality to Hebrew which is a rtl language, the arrow change it's direction and instead of pointing "out", it is now pointing "in". Please refer to image to see how arrow looks in Hebrew and English. Is there a way to control the arrow direction (I want it will point "out" always of course)?

I tried to add the android:layoutDirection="ltr" and android:textDirection="ltr" but it didn't helped.

Thanks for who can answer on this.

enter image description here

Here is the code of the Toolbar layout:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/primaryColor"
app:theme="@style/MyCustomToolBarTheme"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
android:textDirection="ltr"
android:layoutDirection="ltr">

Moti Bartov
  • 3,454
  • 33
  • 42

5 Answers5

8

Finally I succeeded to change the arrow direction.

Well, actually I followed this post: First, I have found some action bar icons and placed a drawable back icons in the project. Then I used this code to set the arrow programmatically:

        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_back);
Community
  • 1
  • 1
Moti Bartov
  • 3,454
  • 33
  • 42
2

The "back" icon is provided by a drawable specified in the homeAsUpIndicator attribute of the theme. You can try to override it and put your own marker (arrow out) it would be something like this:

<style name="Theme.MyTheme" parent="android:Theme.Holo">
    <item name="android:homeAsUpIndicator">@drawable/out_arrow</item>
</style>
Nicolas
  • 663
  • 6
  • 17
0

Below code adjust back arrow direction automatically (Write in your activity):

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Amir
  • 26
  • 3
0

just set android:autoMirrored="true" in your vector drawble's xml.

Hardik Hirpara
  • 2,594
  • 20
  • 34
-1

If you are using Toolbar then this can be a solution:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// getting the back arrow view
View toolbarBack = null;
for (int i = 0; i < toolbar.getChildCount(); i++)
    if (toolbar.getChildAt(i) instanceof ImageButton)
        toolbarBack = toolbar.getChildAt(i);
if (toolbarBack != null) {
    // change arrow direction
    toolbarBack.setRotationY(180);
}
Aref Bahreini
  • 774
  • 8
  • 14