How to disable flipping of the “up” button on the action bar?

三世轮回 提交于 2019-12-12 14:14:53

问题


Background

I've made an "app manager" alternative app, and I wish to add translation for RTL (right to left) languages.

Since I know that as of certain Android version, things got flipped to let words and sentences align correctly, I decided to first switch to such a language and then continue with the translation

The problem

After switching to an RTL language (Hebrew in my case), I've found out that the action bar's up button has the "<" image flipped horizontally:

So now it shows ">" instead.

The question

How do I fix it? It doesn't make sense to see it this way...


回答1:


Well, you can access that ActionBar "up" affordance by calling Resources.getIdentifier and View.findViewById. After that you could rotate it.

    final int upId = getResources().getIdentifier("up", "id", "android");
    final View up = findViewById(upId);
    // Call this to just rotate the icon 180°
    if (getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        up.setRotation(180f);
    }



回答2:


What worked for me was to let the system use the default theme, and not specify Holo. If you can live with that, the Up button will be oriented correctly. Unfortunately this cannot be done if you use AppCompat of course. To make this even more annoying: the flipping of the up button is device specific. It occurs on Samsung devices but not on Google's. The supportsRtl flag is only for API 17 and above, so older Samsung phones cannot be fixed. The issue is apparently the Holo implementation on Samsung devices. Be careful with flipping the icon since on Google phones it will be flipped wrong.

See this: https://code.google.com/p/android/issues/detail?id=68476



来源:https://stackoverflow.com/questions/22602453/how-to-disable-flipping-of-the-up-button-on-the-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!