0

I've created a dead simple Android Studio's starter project (Basic Activity) and I'm getting linkage errors after adding a simple style file in res/values/app_styles.xml:

<resources>
    <style name="MyFab" parent="Widget.MaterialComponents.ExtendedFloatingActionButton">
        <item name="iconTint">?attr/colorOnBackground</item>
        <item name="app:fabSize">mini</item>
        <item name="app:tint">?attr/colorOnPrimary</item>
    </style>
</resources>

The app namespace seems to be unknown to Android Studio, every app:** item is highlighted in red, and build fails with linkage errors:

Android resource linking failed
xxx.myapp.app-mergeDebugResources-43:/values-w600dp-v13/values-w600dp-v13.xml:6: error: style attribute 'app:attr/fabSize' not found.
xxx.myapp.app-mergeDebugResources-43:/values-w600dp-v13/values-w600dp-v13.xml:7: error: style attribute 'app:attr/tint' not found.
error: failed linking references.

What am I doing wrong here? Should I use a different file name/location?

PS: Android Studio Dolphin | 2021.3.1 Patch 1 on Mac x64, fresh install.

Project dependencies:

dependencies {
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
andbi
  • 4,426
  • 5
  • 45
  • 70

1 Answers1

1

You have to remove the app prefix in the attribute name in the style definition.

Pleas note that ExtendedFloatingActionButton is a child class of MaterialButton, rather than FloatingActionButton. This means that several attributes which are applicable to FloatingActionButton have different naming in ExtendedFloatingActionButton or don't exist.

fabSize and tint don't exist for the ExtendedFloatingActionButton.

<style name="MyFab" parent="Widget.MaterialComponents.FloatingActionButton">
    <item name="iconTint">?attr/colorOnBackground</item>
    <item name="fabSize">mini</item>
    <item name="tint">?attr/colorOnPrimary</item>
</style>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thanks for noting the difference, but for example the `app:srcCompat` attribute inside a FAB (icon name) doesn't work as `srcCompat` style item. While all the `android:**` attrs are working as expected. Could you please elaborate more about the "app: vs android:" prefixes? – andbi Oct 25 '22 at 10:47
  • @andbi Not all the attributes in the layout can be defined as an item in the style. About the prefix you can check this question:https://stackoverflow.com/questions/29732512/difference-between-android-and-app-prefix-in-android-xml – Gabriele Mariotti Oct 25 '22 at 11:11