The issue is that you have defined the values for the attributes but haven't defined the attributes itself.
You need to add attrs.xml
under your res
folder with below code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="myCardElevation" format="reference|dimension" />
<attr name="myCardBackgroundColor" format="reference|color" />
<attr name="myCardCornerRadius" format="reference|dimension" />
</resources>
You can see I updated the attribute keys because the ones you used were conflicting with the ones provided by CardView
Your styles.xml
would look like
<style name="CardLayout">
<item name="myCardElevation">@dimen/test_number</item>
<item name="myCardBackgroundColor">@color/red</item>
<item name="myCardCornerRadius">@dimen/test_number</item>
</style>
I would also fix the project, because it is doing a bunch of weird stuff such as packaging an Activity in a library and depending on Butterknife and Constraint Layout deps.
If however you are trying to override the attributes provided by CardView
itself, then you wouldn't need to define attrs.xml
but rather just add a parent
attribute to your style
tag
<style name="CardLayout" parent="CardView">
<item name="cardElevation">@dimen/test_number</item>
<item name="cardBackgroundColor">@color/red</item>
<item name="cardCornerRadius">@dimen/test_number</item>
</style>
Update: with more discussion with OP it is more clear as to why the overriding doesnot work for him.
Since the AAR doesnot bundle build.gradle
file, the dependency of cardview
isnt available when OP includes an AAR in his app.
2 solutions are possible here,
app
module could include cardview
in its build.gradle so that its available when the library compiles from AAR
repositories{
flatDir{
dirs 'libs'
}
}
dependencies {
// This is required because aar doesnot bundle build.gradle i.e the cardview lib needs to be present to be overriden by mylib
compile 'com.android.support:cardview-v7:26.+'
compile(name:'mylibrary-debug', ext:'aar')
}
OP could publish it to some maven repository hosting service such as JitPack, JCenter or Maven central which would include a POM.xml
file along with the aar
file and which defines the dependencies of the aar
file. That way app
module doesnot need to declare the cardview
dependencies, instead that would be downloaded transitively.