【问题标题】:Changing the device system locale not working for Indian languages other than Hindi and Bengali更改设备系统区域设置不适用于印地语和孟加拉语以外的印度语言
【发布时间】:2015-12-18 09:44:43
【问题描述】:

参考this link,我正在构建一个更改android 设备系统区域设置的android 应用程序。它在印度语言印地语和孟加拉语的情况下工作正常,但对于其他印度语言,它不能完全工作(但在某些区域部分改变,比如部分时间的上午/下午)。我的示例代码sn-p:

    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();
    }
}

如果我通过 设置 -> 语言和输入 -> 语言 并在那里更改语言,我的设备并不是没有这些语言支持,有用。但是如何以编程方式进行呢?

【问题讨论】:

  • 你的 logcat 有错误吗?
  • 没有错误,只是没有完全改变。我也关注了this link@icyerasor 的回答,但结果相同。

标签: android locale


【解决方案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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多