简体   繁体   English

多模块项目中的android样式

[英]android styles in a multi module project

I have noticed that in our ide , in a module project (com.android.library) we can see the styles are applied if we execute the application on our device , but can't see them in the layout editor. 我已经注意到,在我们的ide中,在模块项目(com.android.library)中,如果在设备上执行应用程序,则可以看到已应用样式,但是在布局编辑器中看不到样式。

This would be what my package structure looks like 这就是我的包裹结构的样子

app (com.android.application)
-res
--values
---styles.xml

module (com.android.library)
-res
--layouts
---module.xml.

Here in my module.xml layout if i try to access a style mentioned in my app module , it shows as an error in the layout editor 如果我尝试访问我的应用模块中提到的样式,则在我的module.xml布局中,它在布局编辑器中显示为错误 在此处输入图片说明

It does however compile properly and i can even see the styles applied on the device , however its a hassle if I am not able to see the styles applied in the layout editor. 但是,它确实可以正确编译,我什至可以看到应用在设备上的样式,但是如果我看不到布局编辑器中应用的样式,则很麻烦。

Your 'module' module has no dependency on 'app' module (where colors are defined) so it is not visible. 您的“模块”模块不依赖于“应用”模块(定义了颜色),因此不可见。 In order to do it correctly you should create another module with shared styles and make both 'module' and 'app' depend on this shared module. 为了正确执行此操作,您应该使用共享样式创建另一个模块,并使“ module”和“ app”都依赖于此共享模块。

You can also define attributes in your 'module' module and define values for those attributes in your theme which will be defined in 'app'. 您还可以在“模块”模块中定义属性,并在主题中为将在“应用程序”中定义的那些属性定义值。

There is attribute defined for colorPrimary ?android:colorPrimary you can reference this attribute in your module and hope that it is set in yours apps theme. 有为colorPrimary定义的属性?android:colorPrimary您可以在模块中引用此属性,并希望在您的应用程序主题中进行设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM