登录后更改应用程序语言-Android

登录后更改应用程序语言-Android,android,rest,Android,Rest,我的android项目有问题。我正在尝试将应用程序启动时的语言设置为我从REST请求中获得的值。 以下是我在控制器类中的代码: public void onResponse(Call<UserProfile> call, Response<UserProfile> response) { UserProfile userProfile = response.body(); OMSActivity.initLanguage(u

我的android项目有问题。我正在尝试将应用程序启动时的语言设置为我从REST请求中获得的值。 以下是我在控制器类中的代码:

public void onResponse(Call<UserProfile> call, Response<UserProfile> response) {
            UserProfile userProfile = response.body();
            OMSActivity.initLanguage(userProfile);
        }
请求成功,响应中填充了语言字符串,但不知何故,语言没有改变

下面是Activity类的onCreate:

public void changeLang(Context v, String language) {
    Locale locale = new Locale(language);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.setLocale(locale);
    v.getResources().updateConfiguration(config, v.getResources().getDisplayMetrics());
}

public void initLanguage(UserProfile userProfile) {
    switch(userProfile.getLanguage()) {
        case "en": changeLang(this,"en"); break;
        case "de": changeLang(this, "de"); break;
    }

}
super.onCreate(savedInstanceState);
this.omsController = new omsController(this);
omsController.getUserProfile();
setContentView(R.layout.activity_oms);

在另一个活动中,单击按钮即可更改语言。令人惊讶的是,它在那里工作得很好

您的api可能是异步的,因此布局将在api响应之前加载,因此语言更改没有反映出来。@DB377即使我只是在onCreate中尝试changeLang(“de”),但它不起作用,我的changeLang方法可能有问题。