Android - reading out exsting locale values directories
I wonder if there is a way to read out the locale values开发者_如何转开发 of all existing values directories.
Let's say I've got the following directories under my res-Directory
[...] values values-de values-nl [...]
Now I need a method to get back the information that there is a locale of de and nl existing for the directory values.
Is there any way, if yes how?
Any help will be appreciated.
Regards,
Christian
Well, ideally, your app neither knows nor cares what resource sets you have. That is the whole point behind resource sets, after all -- to insulate your app from changes in resources.
That being said, one possibility is to write a script that is part of your build process that generates a file with your requested data (e.g., XML file containing the roster of resource sets) that you then read in at runtime.
Or, arrange to have a "magic value" in each set. For example, in res/values-de/strings.xml
, you could have a lang_de
string, and in res/values-nl/strings.xml
, you could have a lang_nl
string. Then, you can use reflection to iterate over your string resources and find those matching the lang_
pattern. This may be significantly slower than the first option, particularly if you have lots of string resources.
I know of no way to interrogate the system to find out what resource sets are defined.
精彩评论