【问题标题】:Fetch layouts based on selected language of a spinner - Android根据选定的微调器语言获取布局 - Android
【发布时间】:2017-08-22 11:31:31
【问题描述】:

我为多种语言和多种设备定义了layouts,如下所示:

问题:但我需要根据从spinner 中选择的语言而不是设备语言来选择layouts

【问题讨论】:

标签: android android-layout


【解决方案1】:

解决了我的问题:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String languageToLoad = "ar"; // your language you can get this as an input or save it in a file ,or do as your requirement
        Locale locale = new Locale(languageToLoad);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config, null);
        setContentView(R.layout.activity_main);
    }
}

【讨论】:

    猜你喜欢
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多