Android 国际化实现

/**
 * 设置当前语言
 *
 * @param language
 */
public void setLanguage(String language) {
    //获取当前资源对象
    Resources resources = getResources();
    //获取设置对象
    Configuration configuration = resources.getConfiguration();
    //获取屏幕参数
    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
    //设置本地语言
    switch (language) {
        case "_ZH":
            configuration.locale = Locale.CHINA;
            break;
        case "_EN":
            configuration.locale = Locale.ENGLISH;
            break;
    }
    resources.updateConfiguration(configuration, displayMetrics);
    
    SPUtil.logout(LanguageActivity.this);
    MobclickAgent.onProfileSignOff();
    Intent intent = new Intent();
    intent.setClass(LanguageActivity.this, LoginActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();
}

你可能感兴趣的:(Android 国际化实现)