| | |
| | | import android.util.DisplayMetrics; |
| | | import android.util.Log; |
| | | |
| | | import com.driver.igotrip.base.Const; |
| | | import com.driver.igotrip.base.MyApplication; |
| | | import com.driver.igotrip.ui.pub.StartActivity; |
| | | |
| | |
| | | private static Context updateResources(Context context, String language, String country) { |
| | | Resources resources = context.getResources(); |
| | | Locale locale = new Locale(language); |
| | | if (language.equals("ch") || language.equals("")) { |
| | | if (language.equals(Const.Language.CHINESE) || language.equals("")) { |
| | | locale = Locale.CHINA; |
| | | } |
| | | Configuration configuration = resources.getConfiguration(); |
| | |
| | | |
| | | /** |
| | | * @param context |
| | | * @param newLanguage 想要切换的语言类型 比如 "en" ,"zh" |
| | | * @param newLanguage 想要切换的语言类型 比如 Const.Language.ENGLISH ,"zh" |
| | | */ |
| | | @SuppressWarnings("deprecation") |
| | | public static Context changeAppLanguage(Context context, String newLanguage, String country) { |
| | |
| | | //获取想要切换的语言类型 |
| | | Locale locale = new Locale(newLanguage, country); |
| | | configuration.setLocale(locale); |
| | | if (newLanguage.equals("ch")) { |
| | | if (newLanguage.equals(Const.Language.CHINESE)) { |
| | | configuration.setLocale(Locale.CHINA); |
| | | } |
| | | Locale.setDefault(locale); |
| | |
| | | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
| | | LanguageUtil.changeAppLanguage(appContext, language, country); |
| | | } |
| | | SPUtils.save("language", language); |
| | | SPUtils.save(Const.language, language); |
| | | SPUtils.save("country", country); |
| | | } |
| | | |