启动时选择语言 [英] Choosing language at startup

查看:108
本文介绍了启动时选择语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为用户添加启动活动以选择应用程序语言,如何使该活动仅在启动时显示,以及当用户选择语言时,该活动必须永远消失吗?

i want add startup Activity for users to choose app language, how to make this activity to show only at startup and when the user chose the language the activity has to be gone forever?

推荐答案

如果我正确理解您的意思,则希望仅在用户首次运行该应用程序时显示该活动.

If I understand you correctly you wish to display that activity only when the user runs the app for the first time.

好吧,这是您可以做的:

Well, here's what you can do:

1)获取 SharedPreference .用于存储用户是否已选择语言.

1) Get a handle to a SharedPreference. This is to store if the user has already selected the language or not.

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);

2)创建一个SharedPreferences.Editor

2) Create a SharedPreferences.Editor

SharedPreferences.Editor editor = sharedPref.edit();

3)将信息存储在键值中

3) Store the information in a key-value

editor.putBoolean("HAS_SELECTED_LANGUAGE", true);

4)提交更改

editor.commit();

5)检查活动的onCreate()中的"HAS_SELECTED_LANGUAGE"是否为真,如果是,则转到下一个活动/片段/等

5) Check if 'HAS_SELECTED_LANGUAGE' is true in the onCreate() of the activity, if so move on to the next Activity/Fragment/etc

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    ...
    if (sharedPref.getBoolean("HAS_SELECTED_LANGUAGE", false)) {
        //Replace with your action to perform if it is already selected
    }
    ...
}

此外,我们建议将其允许用户在需要时返回并在其他地方更改语言.

Also it would be recomended to allow the user to be able to come back and change the language from somewhere else if and when they require.

希望这可以解决您的问题.

Hope this solve your problem.

这篇关于启动时选择语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆