Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I place my Android styles in different package names?

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/...
like image 380
Johnny Avatar asked Aug 09 '11 10:08

Johnny


1 Answers

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" .../>
like image 88
inazaruk Avatar answered Sep 28 '22 18:09

inazaruk