Detailed explanation of switching language in app
A few days ago, the customer requested to add a function to the app. This function is already very common in the market, that is, switching language in the application. What do you mean, English, Chinese, French, German, Japanese... Switch languages at will.
(the data binding mode is adopted in this case. Ma Ma doesn't have to worry anymore. I can't find the ID in findviewby. Ha ha, I'm kidding)
First, the example figure above:
Code implementation:
The layout file (data binding mode) is very simple, just two lines of text
From the example, we can see that there is a menu in the upper right corner
(since it is multilingual, there must be n strings)
In this case, I created four languages.
OK, after the layout of the menu is written, the next step is to implement the menu function. Remember that there are two sets of codes to implement the menu, one oncreateoptions menu and the other onoptionsitemselected.
Here, we can see that we customize an updateviews () method to change the interface when switching predictions
Publish a language judgment class localehelper
The last thing to do is to customize an application class to set the default language of the app (of course, the application should be applied to the manifest)
This case realizes language switching in the app, with a small amount of code, easy to understand and no garbage code.
Sample code download address: switch language in app
The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!