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

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

问题描述

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

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:

  • 将 minSdkVersion 设置为 17
  • AndroidManifest.xml
  • 中将 android:supportsRtl="true" 添加到我的应用程序标记
  • 将我的左/右属性切换为开始/结束
  • Set minSdkVersion to 17
  • Added android:supportsRtl="true" to my application tag in AndroidManifest.xml
  • Switched my left/right attributes to start/end

起初我手动进行了这些更改,然后我使用了 Android Studio 的重构 -> 在可能的情况下添加 RTL 支持..."菜单项.

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

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

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.

我还需要做些什么来显示 RTL 布局?我希望我错过了一些明显的东西.我正在 API 21 模拟器上对此进行测试.

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.

我继承了其中的一些代码.某些东西可能会覆盖设置并强制其进入 LTR 模式.我制作了一个测试应用程序来测试 RTL 模式,它运行良好.什么样的代码会导致强制 RTL 布局方向"设置被忽略(或被覆盖)?

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)?

我已经检查过是否正确设置了语言环境,确实如此.我还检查了配置,并且设置了ldrtl.我在签名的 apk 文件中验证了 android:supportsRtl 的内容,并且没有任何布局文件具有 android:layoutDirection="ltr".我什至尝试手动放置 android:layoutDirection="rtl" 以尝试强制布局镜像,但这也不起作用.`

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.`

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

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.

如评论中所述,代码取自 Android 开发者博客文章,这解释了为什么这么多其他人遇到了同样的问题.我提交了一个错误报告,此后博客文章已被悄悄更新.这是原始代码,我从中删除了 &= .不要按原样使用以下代码.您需要将 &= 更改为 &:

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天全站免登陆