Android 上实现微信微博上的应用语言切换
程序员文章站
2022-05-09 23:39:22
...
Android 上实现微信微博上的应用语言切换,包含核心代码和ListPreference两部分
核心代码
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
configuration.locale = getLocale(language);
resources.updateConfiguration(configuration, displayMetrics);
然后写一个ListPreference
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Intent intent = new Intent(**ivity, Main**ivity.class);
intent.putExtra("setLanguage", true);
**ivity.start**ivity(intent);
**ivity.finish();
}
核心代码
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
configuration.locale = getLocale(language);
resources.updateConfiguration(configuration, displayMetrics);
然后写一个ListPreference
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Intent intent = new Intent(**ivity, Main**ivity.class);
intent.putExtra("setLanguage", true);
**ivity.start**ivity(intent);
**ivity.finish();
}
AD:真正免费,域名+虚机+企业邮箱=0元
推荐阅读