For example I reference android styles with...
@android:style/...
and my own apps styles with...
@style/...
but how can I separate my styles into other names packages? e.g.
@somePackage:style/...
Unfortunately you can't. You might think that Android Libraries might help you, but this is not the case. That's because Android Libraries are "physically" merged into main application when resources are compiled.
So from aapt
point of view, your application's resources are indistinguishable from any other Android Library resources. Even more, aapt
receives multiple resources directories as input (i.e. path to res
for application, plus paths to all res
directories from references Android Libraries), but at the same time only single AndroidManifest.xml
from application is passed as the "owner" of these resources.
What I want to say, is that even though you can logically group resources (such as styles) into separate Android Libraries, you still can't reference them using these Android Libraries' package names. Only using main application's package name.
For example, you have application with package name com.test.app
and Android Library with com.test.lib
. And the library contains style testStyle
.
The following doesn't work (and there is theoretically nothing that can help you to workaround this):
<TextView style="@com.test.lib:style/testStyle" .../>
While this works fine:
<TextView style="@com.test.app:style/testStyle" .../>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With