我正在开发一个 Android 应用程序,它使用一个库项目,该项目包含工作区中我的多个应用程序正在使用的通用方法。
在库项目中,我有一个类,其中包含一个显示警报对话框和一些 toast 消息的方法。
我正在尝试做的是使用库的“res/values/strings.xml”值来显示那些警报对话框和 toast 消息。 关键是我当然希望根据当前用户的语言采用相关的字符串值。 这样,每当我从其他应用程序使用库中的那些方法时,我就不必在应用程序的“values/strings.xml”中为每个应用程序重新翻译字符串。
提前致谢!
最佳答案
这就是使用库的美妙之处:应用程序中定义的任何字符串都会覆盖库中的字符串。如果我正确理解了您的问题,那么您无需执行任何操作:只需确保字符串名称保持不变即可。
请参阅 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.
关于java - 在库项目中使用库项目的正确 values/strings.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22181755/