首页 > 解决方案 > 我怎样才能获得语言环境的语言?

问题描述

请问题主,如何在android的locale中获取语言?我使用 countrycodepicker 获取国家代码并使用 locale.getLanguage 获取该国家/地区的语言。但是当我选择美国,法国,英国,......它得到错误的语言,如美国 - ikt; 法国-gsw?

String countryCode = ccp.getSelectedCountryNameCode();
        String languageCode = null;
        Locale[] all = Locale.getAvailableLocales();
        for (Locale locale : all) {
            String country = locale.getCountry();
            if(country.equalsIgnoreCase(countryCode)){
                languageCode = locale.getLanguage();
            }
        }

标签: javaandroidlocale

解决方案


要获取当前的 Locale 语言,请使用以下方法:

Locale.getDefault().getLanguage()

推荐阅读