【问题标题】:How to Localize JSON reponse in android studio at run time如何在运行时在 android studio 中本地化 JSON 响应
【发布时间】:2019-02-19 05:22:57
【问题描述】:

我想在 android 应用程序中本地化按钮单击时的 Json 响应,是否可以在运行时本地化 json 响应? 如果可以的话怎么做。

【问题讨论】:

    标签: java android json api localization


    【解决方案1】:

    创建一个语言环境对象:

    Locale aLocale = new Builder().setLanguage("sr").setScript("Latn").setRegion("RS").build();
    

    获取 Json 字符串并设置语言环境:

    public void setLocale(String lang) {
    
    
    
            myLocale = new Locale(lang);
    
            Resources res = getResources();
    
            DisplayMetrics dm = res.getDisplayMetrics();
    
            Configuration conf = res.getConfiguration();
    
            conf.locale = myLocale;
    
            res.updateConfiguration(conf, dm);
    
            Intent refresh = new Intent(this, AndroidLocalize.class);
    
            startActivity(refresh);
    
        }
    

    【讨论】:

    • 总是有一个默认的string.xml,你可以使用getResources().getString(int id)访问和修改它
    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多