参考this link,我正在构建一个更改Android设备系统区域设置的Android应用程序。它适用于印度语印地语和孟加拉语,但对于其他印度语言,它不能完全正常工作(但在某些方面部分改变,如am / pm部分时间)。我的示例代码段:
public void toEnglish(View v){
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
config = am.getConfiguration();
config.locale = Locale.US;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
public void toHindi(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("hi");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
public void toTamil(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("ta");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}
}
如果我通过 设置 - >而不是我的设备中没有这些语言支持。语言与输入 - >语言 并在那里更改语言,它有效。但是如何以编程方式进行呢?
答案 0 :(得分:1)
在初始化语言环境时添加国家/地区字符串对我来说很有用。我在这里添加字符串“IN”。
public void toTamil(View v) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config;
try {
Locale locale = new Locale("ta","IN");
config = am.getConfiguration();
config.locale = locale;
am.updateConfiguration(config);
//Trigger the dirty bit for the Settings Provider.
BackupManager.dataChanged("com.android.providers.settings");
} catch (Exception e) {
e.printStackTrace();
}