Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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 editorenter image description here

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.

like image 591
Muhammad Ahmed AbuTalib Avatar asked Oct 27 '25 09:10

Muhammad Ahmed AbuTalib


1 Answers

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.

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.

like image 100
RadekJ Avatar answered Oct 30 '25 00:10

RadekJ