Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
678 views
in Technique[技术] by (71.8m points)

android - Force RTL layout direction not working for app

I'm trying to add RTL language support in my app (specifically Arabic right now). I'll be supporting English as well. What I've done:

  • Set minSdkVersion to 17
  • Added android:supportsRtl="true" to my application tag in AndroidManifest.xml
  • Switched my left/right attributes to start/end

At first I made these changes manually, then I used Android Studio's "Refactor -> Add RTL Support Where Possible..." menu item.

When I preview my layout files, I can see the RTL preview is properly mirroring the UI; however, even when I use the "Force RTL Layout Direction", my app doesn't display the RTL layout. The system UI is flipped, so that option does work in general.

Is there anything else I need to do to show the RTL layout? I'm hoping I have missed something obvious. I am testing this on an API 21 emulator.

Update

I inherited some of this code. Something might be overriding a setting and forcing this into LTR mode. I made a test application to test out RTL mode and it worked fine. What sort of code could cause the "Force RTL Layout Direction" setting to be ignored (or be overridden)?

Update 2

I've checked that the locale is being set properly, and it is. I also checked the configuration, and ldrtl is set. I verified in the signed apk file that android:supportsRtl made it in and none of the layout files had android:layoutDirection="ltr". I've even tried manually putting android:layoutDirection="rtl" to try to force a layout to mirror, but that didn't work either.`

Update 3

I added another activity to the project, made it the launcher activity, and made sure it isn't connected to any existing code. It is a subclass of Activity. The issue still exists. So theoretically this is a configuration issue. Like I said I checked the AndroidManifest.xml file and all the layout files that are generated, and the RTL support and layout changes all made it in. What could be going wrong with configuration?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Most obscure bug ever. As I mentioned in the question, most of this code was inherited. It ended up being a bitwise operator issue that was screwing up flags for the application. &= was being used instead of & to check if a flag was set.

As noted in the comments, the code was taken from an example in an Android Developers blog post, which explains why so many others have run into this same issue. I filed a bug report, and the blog post has since been silently updated. Here is the original code, which I removed &= from. Do not use the following code as is. You need to change &= to &:

isDebuggable = (appContext.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE) != 0;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...