Question

I'm developing an Android application which uses a library project that contains general methods which are being used by several of my applications in the workspace.

In the library project I have a class with a method that shows alert dialogs and some toast messages.

What I am trying to do is use the library's "res/values/strings.xml" values for those alert dialogs and toast messages. The point is that I ofcourse want the values to be taken are the relevant string values according to the current user's language. This way, whenever I'll use those methods within the library from other applications I won't have to re-translate the strings for each application within the application's "values/strings.xml".

Thanks in advance!

Was it helpful?

Solution

That's the beauty of using libraries: whatever strings are defined in the application override the ones in the library. If I understand your question correctly, you shouldn't have to do anything: just make sure keep the string names the same.

See this quote from the documentation on libraries:

Since the tools merge the resources of a library project with those of a dependent application project, a given resource ID might be defined in both projects. In this case, the tools select the resource from the application, or the library with highest priority, and discard the other resource. As you develop your applications, be aware that common resource IDs are likely to be defined in more than one project and will be merged, with the resource from the application or highest-priority library taking precedence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top