开发者

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 name开发者_StackOverflow中文版s 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" .../>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜