Disable ActionBar RTL Direction

2020-06-03 09:05发布

问题:

Android 4.2 introduced RTL (BiDi) support, to start using it I just follow the instructions (android:supportsRtl attribute to the element in your manifest file and set it “true")

But then my ActionBar logo also changes orientation to the right (Logo is displayed on the right) which I don't want. I do want to use the RTL features but keep the ActionBar oriented to the left...

In other word, how do I use the android:supportsRtl attribute without it changing the ActionBar direction on Android 4.2 when the language direction is RTL

Any suggestions ?

回答1:

First, no sorry, the ActionBar should mirror when you are in RTL mode. This point has been checked and validated by bidi/rtl experts. Setting android:supportsRtl=true means that your app is willing to support RTL layout mirroring. If you do so then the ActionBar (as every Android Framework widgets) will be mirrored as it does not make sense to show it in LTR direction.

Second, your argument about screen size and ergonomics issues for accessing a top left or top right menu is not related to RTL support. If there is such issue in LTR mode then you will have the exact same issue in RTL mode. This is only related to the screen size.

Third, all Android UI Framework widgets are natively supporting RTL mirroring. If you find an issue, please file a bug on the public bug tracking system.

Fourth, Google Apps will support RTL layouts and use those new public RTL APIs when they wish to do so. This is totally decorelated from Android Framework support. The first app to support RTL was the Settings apps (modulo some of its providers that are not yet RTL aware).

Fifth, concerning backport, I am supposing that you are talking about if this feature should be either put in the Support Library or even in older Android releases. For older Android release, this cannot not be done as their codebase is frozen. For the Support Library, we cannot do it as we had to change View and other basic widgets component.

Last be more constructive in you approach and file a bug report if you think you have found an issue or just file a feature request for anything that could be missing.



回答2:

i had the same problem , only that i have a slidingMenu (AKA navigation drawer), so it got even weirder (meaning you click on the top right "up" button and show the drawer on the left...).

there are 2 possible solutions:

  1. by code , in each activity:

    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1)
        getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
    
  2. by theme. edit your own customized theme, and add the correct line. example:

    <style name="AppTheme" parent="@style/Theme.Sherlock.Light">
      <item name="actionBarStyle">@style/CustomActionBarStyle</item>
      <item name="android:actionBarStyle" tools:targetApi="honeycomb">@style/CustomActionBarStyle</item>
    </style>
    
    <style name="CustomActionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar">
      <item name="android:layoutDirection" tools:targetApi="jelly_bean_mr1">ltr</item>
    </style>