Share via

resource attr/colorPrimary (aka com.companyname.handlepdfmauiapp1:attr/colorPrimary) not found.

Jonathan 170 Reputation points
2026-06-12T09:11:30.32+00:00

Hi,

How to resolve it? I got the issue even if I've rebuilt it.

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

2 answers

Sort by: Most helpful
  1. Nancy Vo (WICLOUD CORPORATION) 5,700 Reputation points Microsoft External Staff Moderator
    2026-06-12T10:30:40.1733333+00:00

    Hello @Jonathan ,

    Thanks for your question.

    The error resource attr/colorPrimary not found occurs because MAUI's Android platform uses Material Components themes by default, which require colorPrimary, colorPrimaryDark, and colorAccent to be explicitly defined in your resource files.

    You can refer to these following steps:

    1. Create or update Platforms/Android/Resources/values/colors.xml:

    Platforms/Android/Resources/values/colors.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="colorPrimary">#512BD4</color>
        <color name="colorPrimaryDark">#3700B3</color>
        <color name="colorAccent">#03DAC5</color>
    </resources>
    
    1. Create or update Platforms/Android/Resources/values/styles.xml:

    Platforms/Android/Resources/values/styles.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="MainTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
    </resources>
    
    1. Select both files in Visual Studio and verify Build Action = AndroidResource, otherwise Android will not include them in the resource compilation step.
    2. Delete bin/ and obj/ folders, then do a full rebuild solution

    If the issue persists, please provide the following details so I can investigate further:

    • The full build error log
    • Your .csproj file content

    Please try and let me know if it works. I'd be happy to investigate further.

    I hope this information was helpful. If so, please consider following the guidance to provide your feedback. Thank you.

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-06-12T09:11:43.43+00:00

    attr/colorPrimary and attr/colorPrimaryDark are built‑in Android theme attributes. The error

    resource attr/colorPrimary (aka com.companyname.handlepdfmauiapp1:attr/colorPrimary) not found

    means the build cannot resolve that attribute in the current project.

    To resolve it in a .NET for Android / MAUI app, ensure that:

    1. The attributes are referenced from the correct namespace
      • When using Android framework attributes in XML, reference them via the Android namespace, for example:
             <item name="android:colorPrimary">@color/your_primary_color</item>
             <item name="android:colorPrimaryDark">@color/your_primary_dark_color</item>
        
      • Do not declare colorPrimary or colorPrimaryDark as custom attributes under your app’s package; they already exist as framework attributes.
    2. The app theme is based on a Material/AppCompat theme that defines these attributes
      • In styles.xml, ensure the app theme inherits from a Material/AppCompat theme that supports colorPrimary and colorPrimaryDark, for example:
             <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
                 <item name="colorPrimary">@color/your_primary_color</item>
                 <item name="colorPrimaryDark">@color/your_primary_dark_color</item>
             </style>
        
      • Then set this theme in the Android manifest or in the MAUI project’s Android configuration.
    3. Clean and rebuild after fixing XML
      • After correcting the theme and attribute references, run a full clean and rebuild so that the generated Resource.Attribute.ColorPrimary and Resource.Attribute.ColorPrimaryDark constants (with IDs 16843827 and 16843828) are correctly picked up from the Android framework.

    If any custom library or layout is still referencing @attr/colorPrimary without a compatible theme, update that library/theme to use a Material/AppCompat base theme so the attributes are available.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.