强制RTL布局方向不适用于应用 [英] Force RTL layout direction not working for app

查看:187
本文介绍了强制RTL布局方向不适用于应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序中添加RTL语言支持(现在特别是阿拉伯语).我也会支持英语.我所做的:

  • 将minSdkVersion设置为17
  • AndroidManifest.xml
  • 中的我的应用程序标签中添加了android:supportsRtl="true"
  • 将左/右属性切换为开始/结束

首先,我手动进行了这些更改,然后使用了Android Studio的重构->尽可能添加RTL支持..."菜单项.

预览布局文件时,可以看到RTL预览正确地反映了UI;但是,即使我使用强制RTL布局方向",我的应用也不会显示RTL布局.系统用户界面已翻转,因此该选项通常可以正常工作.

我还需要做些其他的事情来显示RTL布局吗?我希望我错过了一些显而易见的事情.我正在API 21仿真器上对此进行测试.

更新

我继承了其中一些代码.某些情况可能会覆盖设置并将其强制为LTR模式.我制作了一个测试应用程序以测试RTL模式,并且运行良好.哪种代码可能导致强制RTL布局方向"设置被忽略(或被覆盖)?

更新2

我检查了是否正确设置了语言环境.我还检查了配置,并设置了ldrtl.我在签名的apk文件中验证了android:supportsRtl是否已加入该文件,并且布局文件都没有android:layoutDirection="ltr".我什至尝试过手动放置android:layoutDirection="rtl"来尝试强制布局进行镜像,但这还是行不通的.

更新3

我向项目添加了另一个活动,使其成为启动程序活动,并确保它未连接到任何现有代码.它是Activity的子类.问题仍然存在.因此,从理论上讲,这是一个配置问题.就像我说的那样,我检查了AndroidManifest.xml文件和所有生成的布局文件,并且所有RTL支持和布局更改都加入了.配置可能出什么问题了?

解决方案

有史以来最晦涩的错误.正如我在问题中提到的那样,大多数代码都是继承的.最终,这是一个按位操作符问题,正在为应用程序加紧标记.使用&=而不是&来检查是否设置了标记.

如评论中所述,该代码摘自 Android开发者博客文章,它解释了为什么这么多其他人也遇到了同样的问题.我提交了一个错误报告,此博客帖子此后进行了静默更新.这是原始代码,我从中删除了&=. 请勿原样使用以下代码.您需要将&=更改为& :

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

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?

解决方案

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;

这篇关于强制RTL布局方向不适用于应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆