我以编程方式更改了我的应用程序的locale
,如下所示:
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale("cn");
res.updateConfiguration(conf, dm);
在此之后,我想刷新我当前显示的 fragment View 以使用新的区域设置显示。
所以,我首先获取当前 fragment (即backstack
中最新的 fragment ):
BackStackEntry latestEntry=fragMgr.getBackStackEntryAt(fragMgr.getBackStackEntryCount()-1);
String str=latestEntry.getName();
Fragment fragment=fragMgr.findFragmentByTag(str);
得到当前显示的 fragment 后,我想刷新它的 View ,但是怎么做呢?在Android中是否可以刷新 fragment 的 View
最佳答案
您可以像下面这样简单地分离和附加 fragment
Fragment currentFragment = getFragmentManager().findFragmentByTag("FRAGMENT");
FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
fragTransaction.detach(currentFragment);
fragTransaction.attach(currentFragment);
fragTransaction.commit();
这将刷新 View 并且区域设置将改变
关于android - 是否可以刷新 fragment 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9889175/