在我的活动中,我以编程方式将区域设置更改为RTL语言。在此之后,我希望我的布局刷新根据RTL区域设置,而不是重新启动活动。
下面是实现该功能的代码:
public void setLocale()
{
    String arr[] = LangCode.split("_");
    Configuration config = new Configuration();
    DisplayMetrics dm = this.getResources().getDisplayMetrics();
    Locale locale = new Locale(arr[0], arr[1]);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Locale.setDefault(locale);
        config.setLocale(locale);
        config.setLayoutDirection(locale);
    } else {
        config.locale = locale;
    }
    this.getResources().updateConfiguration(config, dm);
}在那之后,我试图使这个观点无效,但没有成功。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    findViewById(R.id.intro_lang_ll).invalidate();
    findViewById(R.id.intro_lang_ll).requestLayout();
}我希望我的视图应该在我更改区域设置而不重新启动活动时立即镜像自己。
发布于 2015-10-29 14:12:13
如果你不想刷新你的整个活动,那么你可以按如下所示使用invalidate():
public void invalidate () 它会使整个视图失效。
如果视图可见,将在将来的某个时候调用onDraw(Canvas)。这必须从UI线程调用。若要从非UI线程调用,请调用postInvalidate()。
发布于 2015-10-29 19:02:25
你可以试试这个
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);它对我很有效..没有延误
https://stackoverflow.com/questions/33406581
复制相似问题