android - 是否可以刷新 fragment 的 View

标签 android android-layout android-intent android-widget android-fragments

以编程方式更改了我的应用程序的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/

相关文章:

android - 为什么我不能在 Kotlin 中为 int var 设置 Lateinit ?

java - 如何更改未单击的按钮的背景颜色?

android - 无法加载新的空白 Activity - Android 教程

java - 如何修复 "startActivity() in ContextCompat cannot be applied to?"

android - 在 Activity 启动之前包含进度条的过程是什么

android - echo $ANDROID_HOME 在 Mac 中返回空白

android - 如何创建这样的 ListView? (交通柜台)

android - 媒体提取器显示 "failed to instantiate extractor"

Android 分辨率和模拟器没有选择正确的图像

java - IntentService 中的路由 Intent