安卓应用中阿拉伯语支持的UI设计

5
我正在尝试为我的Android应用提供阿拉伯语支持。Android 2.3默认提供阿拉伯语支持。因此,我想知道在为Android提供阿拉伯语支持时是否需要进行任何UI更改。
由于阿拉伯文是从右向左书写的,因此我需要遵循哪些约束条件来设计Android UI布局并编码?
否则,Android本身会负责读取我们输入的数据,无论它是从右向左键入的还是从左向右键入的。
有人能帮我解决这个问题吗?

我也遇到了同样的问题,有人能提供建议吗? - Arpit Garg
我遇到了同样的问题。我认为可以制作阿拉伯语的从右到左的XML,以及英语的从左到右的XML。每个控件的文件名和ID应该相同。还有其他更简单的方法吗? - Hiren Dabhi
@HirenDabhi RTL支持很容易实现,一旦你养成使用Start和End而不是Right和Left的习惯。阅读我的评论以获取更多细节。 - Teovald
2个回答

1

我已经使用了这段代码,它完美地运行了,请尝试一下...

public static void change_setting_arabic(Context con) {
            try {
                Locale locale = new Locale("ar");

                Class amnClass = Class.forName("android.app.ActivityManagerNative");
                Object amn = null;
                Configuration config = null;

                // amn = ActivityManagerNative.getDefault();
                Method methodGetDefault = amnClass.getMethod("getDefault");
                methodGetDefault.setAccessible(true);
                amn = methodGetDefault.invoke(amnClass);

                // config = amn.getConfiguration();
                Method methodGetConfiguration = amnClass
                        .getMethod("getConfiguration");
                methodGetConfiguration.setAccessible(true);
                config = (Configuration) methodGetConfiguration.invoke(amn);

                // config.userSetLocale = true;
                Class configClass = config.getClass();
                Field f = configClass.getField("userSetLocale");
                f.setBoolean(config, true);

                // set the locale to the new value
                config.locale = locale;

                // amn.updateConfiguration(config);
                Method methodUpdateConfiguration = amnClass.getMethod(
                        "updateConfiguration", Configuration.class);
                methodUpdateConfiguration.setAccessible(true);
                methodUpdateConfiguration.invoke(amn, config);

            } catch (Exception e) {
                // TODO: handle exception
                Log.d("error lang change-->", "" + e.getMessage().toString());
            }
        }

0
一个小技巧来自 Android 团队的 Roman Nurik:
为了更好地支持 RTL,请使用 START 和 END 的重力,而不是 LEFT 和 RIGHT。虽然这些常量仅在 API 14 中定义 [0],但它们向后兼容,因为 (1) 它们在编译时被内联,(2) 它们在早期设备上与 LEFT 和 RIGHT 在功能上是等效的,因为它们的最低有效字节相同:

START = 0x00800003
LEFT = 0x00000003
END = 0x00800005
RIGHT = 0x00000005

您可以通过以下方式查看 START 和 LEFT 之间的区别:
<TextView layout_width=match_parent, gravity=start, text=[希伯来字符]>
由于重力为 start,文本布局将查看您的希伯来字符并将文本对齐到 TextView 的右边界,而不是左边界。请注意,TextView 的默认水平重力是 start,而不是 left。

因此,left 始终是 left,right 始终是 right,但是 start 和 end 可以是 left 或 right,具体取决于语言环境。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接