7

I'm trying to use a custom with Theme.AppCompat.NoActionBar but the IDE throws the error that the named resources cannot be found. Kindly assist.Any help would be greatly appreciated.

The styles.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowActionBar">false</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorPrimaryLight">@color/primary_light</item>
        <item name="colorAccent">@color/accent</item>
        <item name="textColorPrimary">@color/primary_text</item>
        <item name="textColorSecondary">@color/secondary_text</item>
        <item name="iconColor">@color/icons</item>
        <item name="dividerColor">@color/divider</item>
    </style>    
</resources>

The colors.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primary">#FF9800</color>
    <color name="primary_dark">#F57C00</color>
    <color name="primary_light">#FFE0B2</color>
    <color name="accent">#03A9F4</color>
    <color name="primary_text">#212121</color>
    <color name="secondary_text">#727272</color>
    <color name="icons">#212121</color>
    <color name="divider">#B6B6B6</color>
</resources>
Kaushik
  • 6,150
  • 5
  • 39
  • 54
Kabs
  • 227
  • 2
  • 4
  • 12

7 Answers7

13

Just Build > Clean Project Then File > Invalidate Caches / Restart Project.

Aref Bahreini
  • 774
  • 8
  • 14
2

Rename Your xml Name, Set color.xml instead colors.xml under values folder. Then Build > Clean Project Then Restart Project .

Or try this way

 <resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="green">#00ff00</color>

Reference

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
2

Make sure you don't have any imports like mine below

import android.R

This imports the wrong resource.

Gates Wang
  • 23
  • 4
1

I was getting the following error which seems to be similar to yours

error: resource color/color_primary (aka com.example.android.test31july:color/color_primary) not found.

I went to colors.xml and created exactly the color resource named "color_primary" and the problem vanished.

Sunil Kumar
  • 6,112
  • 6
  • 36
  • 40
  • For me, it the colors.xml had a reference that didn't exist. I fixed the reference, and cleaned the project to make the error disappear. What Kumar wrote should be the correct answer. – Rickard Elimää Dec 04 '18 at 12:29
0

Rebuilding can take a long time.

Simply remove the offending line and re-add it.

Nolan Amy
  • 10,785
  • 5
  • 34
  • 45
0

make sure you use the color tag instead of any other tag.

<color name="name">#123</color>
behrad
  • 1,228
  • 14
  • 21
0

try this

ContextCompat.getColor(getContext(), R.color.red800)
Harshad pk
  • 71
  • 2
  • 4