'Same dimen in App and Library
Can someone let me know, what if there is some dimen by same name in app and a library.
dimen.xml inside app
<dimen name="activity_horizontal_margin">10dp</dimen>
dimen.xml inside library
<dimen name="activity_horizontal_margin">12dp</dimen>
Which one will be used at runtime?
I can try it, but I will not be clear for the reason to being used as final value.
Solution 1:[1]
You can try to redefine size in your dimensions.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<dimen name="activity_horizontal_margin" tools:override="true">12dp</dimen>
</resources>
Use with care as this is a hack, not an actual solution. The solution might not work if the resource's name is changed in the future Library release.
Solution 2:[2]
I think the answer would be:
It depends on what layout is being populated, if it's an activity layout from an app module then app's dimen will be used and vice versa..
Solution 3:[3]
This is a great question I don't know why it got downvoted. While the selected answer is true there is slightly more nuance to it, Android chooses the "most specific" resource which takes precedence over app resource values.
e.g. consider the boolean <bool name="isTablet">true</bool> in a library, setup like so:
- values - false
- values-sw600dp - true
And in an app like so:
- values - false
- values-sw600dp-land - true
What is the value of the boolean on a 1280x800 portrait tablet when called from the app?
The answer is true, even though the app specified it to be true in landscape only!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Ümañg ßürmån |
| Solution 3 |
