Util.java 文件源码

java
阅读 37 收藏 0 点赞 0 评论 0

项目:content-farm-blocker-android 作者:
@SuppressWarnings("deprecation")
public static void detectLanguage(Context context) {
    SharedPreferences setting = PreferenceManager
            .getDefaultSharedPreferences(context);
    String language = setting.getString(Util.PREF_LANGUAGE, "auto");
    Resources res = context.getResources();
    Configuration conf = res.getConfiguration();
    switch (language) {
        case "en":
        case "zh":
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                conf.setLocale(new Locale(language));
            } else {
                conf.locale = new Locale(language);
            }
            break;
        default:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                conf.setLocale(Resources.getSystem().getConfiguration().getLocales().get(0));
            } else {
                conf.locale = Resources.getSystem().getConfiguration().locale;
            }
    }
    DisplayMetrics dm = res.getDisplayMetrics();
    res.updateConfiguration(conf, dm);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号