Reputation: 179
I upgraded my project ( Ionic Framework ) from Android to AndroidX. After that, my project started throwing errors while rebuilding. It is giving "AAPT: error: resource color/colorPrimary (aka io.aide.aide:color/colorPrimary) not found." from file "{Project}\android\app\src\main\res\values\styles.xml".
Here is my styles.xml
file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:background">@null</item>
</style>
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
<item name="android:background">@drawable/splash</item>
</style>
</resources>
The folder of styles.xml is as below
In the below post, they suggested to create a color file. Error:(387, 5) error: resource color/colorPrimary (aka com.example.kubix.r3vir3dv3:color/colorPrimary) not found
I am beginner and I do not know what should be in the color file.
Can any one give me any suggestions to overcome this problem?
Upvotes: 15
Views: 49392
Reputation: 161
You need to define the color resources in res/values/colors.xml to avoid the error.
Example :
for @color/colorPrimary
write the following code in res/values/colors.xml
<color name="colorPrimary">#3F51B5</color>
for @color/colorPrimaryDark
write the following code in res/values/colors.xml
<color name="colorPrimaryDark">#303F9F</color>
for @color/colorAccent
write the following code in res/values/colors.xml
<color name="colorAccent">#FF4081</color>
Upvotes: 3
Reputation: 6432
In your project, you need to create color.xml file
Right click on values > New > Values Resource File > Enter File Name "color.xml"
Path:
res/values/color.xml
This is how your color.xml will look like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">@color/blue_1</color>
<color name="colorPrimaryDark">@color/blue_1</color>
<color name="colorAccent">@color/blue_5</color>
<color name="blue_1">#00101f</color>
<color name="blue_5">#0078ff</color>
</resources>
Upvotes: 21