塞尔维亚拉丁语和塞尔维亚西里尔字母 [英] Serbian latin and Serbian Cyrillic in android

查看:642
本文介绍了塞尔维亚拉丁语和塞尔维亚西里尔字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式将应用中的语言环境更改为android应用中的塞尔维亚语拉丁语? 据我了解,我可以通过这种方式做到这一点:

Is it possible to change programmatically Locale in the app to Serbian Latin in android app? As i understand i can do it in this way:

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

但是它仅在21 API中可用.但是我有minsdk = 16

But it is available only in 21 API. But i have minsdk = 16

推荐答案

希望我还不算太晚:)
这是我解决的方法,您需要使用相应的strings.xml制作不同的values文件夹在其中,请记住,我想将拉丁语设置为默认值,因此我将en(仅用于纯值文件夹)和西里尔字母作为选择,因此将其置于ca(values-ca文件夹)中,依此类推.

Hope I'm not too late :)
This is how I solved it, you need to make different values folder with corresponding strings.xml in it, keep in mind that I wanted to have latin as default so I use en (just plain values folder) for that and cyrillic as a choice so its in ca (values-ca folder) and so on...

public static void language(String s) {
        switch (s) {
            case "Srpski":
                setLocale("en");
                break;
            case "Српски":
                setLocale("ca");
                break;
            case "Hrvatski":
                setLocale("hr");
                break;
            case "Македонски":
                setLocale("mk");
                break;
            case "Slovenski":
                setLocale("sl");
                break;
        }
    }

    public static void setLocale(String lang) {
        // ctx is my Context
        if (ctx == null) {
            ctx = MainActivity.getContext();
        }
        Locale mLocale = new Locale(lang);
        Locale.setDefault(mLocale);
        Configuration mConfiguration = new Configuration();
        mConfiguration.locale = mLocale;    //DEPRECATED .locale
        ctx.getResources().updateConfiguration(mConfiguration, ctx.getResources().getDisplayMetrics());     //DEPRECATED updateConfiguration
    }

这篇关于塞尔维亚拉丁语和塞尔维亚西里尔字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆