Can I put my Android styles in different package names?

For example, I reference Android styles with ...

@android:style/... 

and my own application styles with ...

 @style/... 

but how can I separate my styles in other name packages? eg

 @somePackage:style/... 
+6
source share
1 answer

Sorry, you can’t. You might think that Android libraries might help you, but that is not the case. This is because Android libraries are “physically” combined into the main application when compiling resources.

So, in terms of aapt your application resources are indistinguishable from other Android library resources. Moreover, aapt receives several resource directories as input (i.e. the path to res for the application, plus the paths to all res directories from the links of Android libraries), but at the same time only one AndroidManifest.xml is transferred from the application as the "owner" of these resources.

I want to say that even if you can logically group resources (for example, styles) into separate Android libraries, you still cannot reference them using the package names of Android libraries. Only using the name of the main application.


For example, you have an application with the package name com.test.app and an Android library with com.test.lib . And the library contains the testStyle style.

The following steps do not work (and theoretically, nothing can help you think about this):

 <TextView style="@com.test.lib:style/testStyle" .../> 

So far, this works great:

 <TextView style="@com.test.app:style/testStyle" .../> 
+3
source

Source: https://habr.com/ru/post/894621/


All Articles