Reputation: 13369
I am trying to provide Arabic Language support for my Android app. Arabic Language support is provided by default by Android 2.3. So, I want to know if there are any UI changes that I need to do while providing support for Arabic language in Android.
As the letters in Arabic were written from right to left, what are the constraints that I need to follow in Android UI layout design and also in coding?
Or else otherwise will Android itself take care of reading the data we entered, whether it is typed from right to left.
Can anyone help me in sorting out this issue?
Upvotes: 5
Views: 1735
Reputation: 4389
A little pro-tip from Roman Nurik (from the Android team):
Use gravities of START and END instead of LEFT and RIGHT for better RTL support. Although the constants are only defined in API 14 [0], they are backward compatible because
(1) they're inlined at compile time and (2) they're functionally equivalent to LEFT and RIGHT on earlier devices because of their least-significant bytes:
START = 0x00800003
LEFT = 0x00000003
END = 0x00800005
RIGHT = 0x00000005
You can see the difference between START and LEFT with
<TextView layout_width=match_parent, gravity=start, text=[hebrew characters here]>
the text layout will see your Hebrew characters and align text to the right boundary of the TextView instead of the left because of gravity=start. And note, the default horizontal gravity of TextView is start, not left.
So, left is always left and right is always right, but start and end can be either left or right, depending on the locale.
Upvotes: 0
Reputation: 722
I have use this code and working perfect try it..
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());
}
}
Upvotes: 1