多模块应用不反映基本活动的变化
我正在构建一个示例多模块应用程序,其中我有1个库通用,该应用具有MainAttivity和一个简单的文本视图。 TextView在XML中没有定义的文本,MainActivity具有binding.tvtext.text = getString(r.string.url)
。
我有2个模块的Google和Facebook,那里没有活动,它们的清单包括:
<activity android:name="com.example.common.WebViewActivity"
android:exported="true">
我将库的库列为两个模块的依赖性(实现项目(路径:':':common'))。 TextView出现空白,当它应显示 www.google.com 或 www.facebook.com ,但是有趣的是,如果我将xml的文本设置为@string/url ,它可以工作非常适合两个模块。甚至像TextColor这样的变化也不会反映在Main Activitive中!
这是一个问题,因为我想在活动中加载WebView,每个模块都有不同的URL,但是没有任何更改被拾取。有建议吗?
I'm building a sample multi module app where I have 1 library common, which has a MainActivity and a simple TextView. The TextView has no text defined in the xml and the MainActivity has binding.tvText.text = getString(R.string.url)
.
I have 2 modules google and facebook, where there is no Activity, their manifests include:
<activity android:name="com.example.common.WebViewActivity"
android:exported="true">
and I have listed the library common as a dependency for both modules (implementation project(path: ':common')). The TextView appears blank, when it should show either www.google.com or www.facebook.com, but what's interesting is that if I set the xml's text to @string/url
, it works perfectly for both modules. Even changes like textColor aren't reflected in the MainActivity!
This is an issue as I want to load a WebView in the Activity with a different url for each module, but none of the changes are picked up. Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个模块都有其自己的
r
资源类,它引用了同一模块中的资源。当您在运行时代码中使用r.string.url
时,它明确拉动com.mybasemodulepackage.r.string.url
资源,而不是可能定义的一些资源在其他一些模块中。当您在XML中使用
@string/url
时,布局充气器将从最接近的资源范围中提取资源,该资源来自该应用程序所构建的软件包名称。我不确定最好的解决方案,如果将其设置为XML不适合您的情况。您可能会有这项常见的活动从传递的附加功能中获取URL。然后,每个模块打开活动时都可以通过URL。
Each module has it's own
R
resources class that references the resources in that same module. When you useR.string.url
in your runtime code, it is explicitly pulling thecom.mybasemodulepackage.R.string.url
resource, not some resource that might be defined in some other module.When you use
@string/url
in your XML, the layout inflator pulls the resource from the closest resource scope, the one from the package name that the app was built with.I'm not sure of the best solution, if setting it in XML is not appropriate for your situation. You might have this common activity acquire the URL from the extras passed to it. Then each module can pass the URL when they open the activity.