How to make an application in two languages by changing the language in the Settings menu? Android studio

Asked

Viewed 713 times

1

inserir a descrição da imagem aqui I would like to do this manually via a click, Portuguese or English language. and search for the correct string.

public Boolean onCreateOptionsMenu(Menu menu) { getMenuInflater(). inflate(R.menu.menu_main, menu); Return true; }

public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

1 answer

2


The best way to do this would be to add different.xml strings in different resource folders, for example:

res/
    values/
           strings.xml // Idioma padrão 
    values-pt-rBr/
           strings.xml // Idioma português Brasil

More in the documentation android.

Or you can change manually as the example of this website.

  • When I create the values-en folder for example, it is hidden!

  • If you are in Android Studio it is usually hidden until you add some file inside, I usually do this by changing the display mode of the project from android to project or simply doing it manually through the Windows file explorer. Then you see in the values folder in the project a string folder, which will show your string files.

  • Good! I added! now the question topic is missing.how to change from one to another.

  • Generally Android chooses the language of your application based on its strings.xml, in the second link, the post Author shows how to create a method to change the language

Browser other questions tagged

You are not signed in. Login or sign up in order to post.