Opa*_*Web 5 android android-fragments
我的应用广泛使用片段.它应该支持3种语言 - 英语,阿拉伯语和库尔德语.主屏幕包含一个导航抽屉,其中包含一个选项菜单,其中一个选项是打开语言选择器对话框的语言.语言选择器有3个按钮 - 英语,库尔德语和阿拉伯语点击一个按钮就可以改变语言 -
private void setLocale(String code){
Configuration config=new Configuration();
Locale locale = null;
locale=new Locale(code);
Locale.setDefault(locale);
config.locale=locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
dismiss();
}
Run Code Online (Sandbox Code Playgroud)
我已将以下代码添加到onConfigurationChange -
FragmentManager fragmentManager = getSupportFragmentManager();
int count=fragmentManager.getBackStackEntryCount();
BackStackEntry latestEntry=(BackStackEntry) fragmentManager.getBackStackEntryAt(count-1);
String str=latestEntry.getName();
Fragment fragment=fragmentManager.findFragmentByTag(str);
if(fragment==null){
return;
}
FragmentTransaction fragTransaction = fragmentManager.beginTransaction();
fragTransaction.detach(fragment);
fragTransaction.attach(fragment);
fragTransaction.commit();
Run Code Online (Sandbox Code Playgroud)
我已经在android清单中添加了以下内容 -
android:configChanges="locale"
Run Code Online (Sandbox Code Playgroud)
但似乎没有发生任何事情.我也尝试过 - 没有太多运气可以刷新片段的视图.任何帮助表示赞赏.提前致谢.
在我看来,如果您监听配置更改,您还应该重写onConfigurationChangedFragment 或托管活动中的方法,然后根据需要使用新的区域设置更新 UI,而不是分离并重新附加您只需将方法填充到子项中活动并根据需要重新填充所有字段
| 归档时间: |
|
| 查看次数: |
3649 次 |
| 最近记录: |