I'm getting this error in my code:
Error: No resource found that matches the given name (at 'background' with value #color/red').
Here is my TextView:
<TextView
android:id="#+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/prizeFund"
android:background="#color/red">
</TextView>
And the color definition, in colors.xml in res/values:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#ff0000</color>
<color name="green">#00ff00</color>
<color name="blue">#0000ff</color>
</resources>
Try to clean your project The R.java file will be regenerated for you
On eclipse go to Project---->Clean..
also the resources must be in strings.xml not colors.xml
below an exemple of the strings.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Strings Resources -->
<string name="animations">Animations: </string>
<string name="compass">Compass: </string>
<!-- Colors Resources -->
<color name="opaque_white">#FFFFFFFF</color>
<color name="gray">#FF888888</color>
</resources>
Related
I have an Android app I am trying to build, and I am getting the following error:
Apparently it was unable to compile the values resource file.
I have followed some of the suggestions in this StackOverflow question. I've gone through my strings.xml file and put a backslash before characters like the colon, the exclamation point, the full stop etc. I have looked at the colours and they do appear to be correct:
I have rebuilt several times, and done several cleans. I even restarted Android studio after putting the backslash into my strings.xml. I have tried looking in logs, but I cannot see where the issue is. Is there anything else I need to check?
Contents of resource files are below:
colours.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#c86f22</color>
<color name="BackgroundAccent">#ff424242</color>
</resources>
dimens.xml:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>
font_certs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="com_google_android_gms_fonts_certs">
<item>#array/com_google_android_gms_fonts_certs_dev</item>
<item>#array/com_google_android_gms_fonts_certs_prod</item>
</array>
<string-array name="com_google_android_gms_fonts_certs_dev">
<item>
MIIEqDCC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2y5b+3JKkedxiLDmpHpDsz2WCbdxgxRczfey5YZnTJ4VZbH0xqWVW/8lGmPav5xVwnIiJS6HXk+BVKZF+JcWjAsb/GEuq/eFdpuzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/CxURaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
</item>
</string-array>
</resources>
ic_launcher_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#808080</color>
</resources>
ids.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="CardTicket" type="id">0000001</item>
<item name="tempCard" type="id">0000002</item>
</resources>
preloaded_fonts.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="preloaded_fonts" translatable="false">
<item>#font/advent_pro_medium</item>
</array>
</resources>
strings.xml:
<resources>
<string name="app_name">FixITApp</string>
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_password">Password (optional)</string>
<string name="action_sign_in">Sign in or register</string>
<string name="action_register">Register</string>
<string name="back">Back</string>
<string name="Sign_in_here">Already have an account\? Sign in here\:</string>
<string name="Register_here">No Account\? Register here for your free account\!</string>
<string name="ExitToMenu">Exit to Main Menu</string>
<string name="Exit_App">Exit Application</string>
<string name="action_sign_in_short">Sign in</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions\."
</string>
<string-array name="IssueTypes">
<item> </item>
<item>Please Select a value\:</item>
<item>PC</item>
<item>Server</item>
<item>Laptop</item>
<item>Monitor</item>
<item>Keyboard</item>
<item>Mouse</item>
<item>RAM</item>
<item>HardDrive</item>
<item>Projector</item>
<item>Interactive Board</item>
<item>Other</item>
</string-array>
<string-array name="Severities">
<item> </item>
<item>Please Select a value\:</item>
<item>Critical</item>
<item>High</item>
<item>Moderate</item>
<item>Low</item>
</string-array>
</resources>
styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.PopUpTing">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
</style>
</resources>
OK, so I got it working.
The problem was in ids.xml, which contained the following:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="CardTicket" type="id">0000001</item>
<item name="tempCard" type="id">0000002</item>
</resources>
I ran the build again using --scan, and learnt that <item> inner element must either be a resource reference or empty. I removed the 0000001 and 000002 from the IDs and it is now building.
I m making a simple single screen app
and I m trying to change background color of layout randomly from 11 colors
on button click, i know how to use random method but cant figure out how to store 11 colors in array and how to access them
This like may tell you what i want
this is the layout i want to change color of
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
tools:context=".MainActivity"
android:id="#+id/bg"
tools:layout_editor_absoluteY="25dp">
Here my colorarray.xml
<?xml version="1.0" encoding="utf-8"?>
<!--bg color-->
<color name="color1">#7e3ff2</color>
<color name="color2">#ff6e39</color>
<color name="color3">#f2366e</color>
<color name="color4">#e800c3</color>
<color name="color5">#b402ee</color>
<color name="color6">#01abff</color>
<color name="color7">#00d5a0</color>
<color name="color8">#00d5c7</color>
<color name="color9">#7763cf</color>
<color name="color10">#e3e17c</color>
<color name="color11">#c7984b</color>
<array name="background">
<item>#color/color1</item>
<item>#color/color2</item>
<item>#color/color3</item>
<item>#color/color4</item>
<item>#color/color5</item>
<item>#color/color6</item>
<item>#color/color7</item>
<item>#color/color8</item>
<item>#color/color9</item>
<item>#color/color10</item>
<item>#color/color11</item>
</array>
Edit
Since above problem is now solved
now how can i change status bar color accordingly to same color as background
<!--status bar bg color-->
<color name="darkcolor1">#3b00e0</color>
<color name="darkcolor2">#e64705</color>
<color name="darkcolor3">#c80050</color>
<color name="darkcolor4">#bd00ae</color>
<color name="darkcolor5">#7300e0</color>
<color name="darkcolor6">#0c89db</color>
<color name="darkcolor7">#009d5c</color>
<color name="darkcolor8">#009d5c</color>
<color name="darkcolor9">#443cb6</color>
<color name="darkcolor10">#b6ae39</color>
<color name="darkcolor11">#ceac54</color>
<array name="statusBarBg">
<item>#color/darkcolor1</item>
<item>#color/darkcolor2</item>
<item>#color/darkcolor3</item>
<item>#color/darkcolor4</item>
<item>#color/darkcolor5</item>
<item>#color/darkcolor6</item>
<item>#color/darkcolor7</item>
<item>#color/darkcolor8</item>
<item>#color/darkcolor9</item>
<item>#color/darkcolor10</item>
<item>#color/darkcolor11</item>
</array>
I’m trying to set another color in in below mentioned attribute but it showing me error.
<TextView
android:text="Happy Birthday! ABHISHEK :)"
android:background="#android:color/blue"
android:layout_width="300dp"
android:layout_height="50dp" />
You are setting blue color which is not available on #android:color, you can set color android:background="#android:color/holo_blue_dark" or,
On your colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#441969</color>
<color name="colorPrimaryDark">#361454</color>
<!--<color name="colorAccent">#361454</color>-->
<color name="colorAccent">#FFB700</color>
<color name="colorYellow">#FFB700</color>
<color name="primaryLight">#7E4995</color>
<color name="blue">#2ea747</color>
<color name="black">#000000</color>
</resources>
Use Resource color you set your textview background color:
By xml :
android:background="#color/blue"
By Java Code :
textView.setBackgroundResource(R.color.blue);
Reference : https://android--examples.blogspot.in/2015/01/textview-background-color-in-android.html
If you Want to apply color from android resource then there are three combination available for you .
holo_blue_dark , holo_blue_bright , holo_blue_light
SO you can use one of this like.
<TextView
android:text="Happy Birthday! ABHISHEK :)"
android:background="#android:color/holo_blue_dark"
android:layout_width="300dp"
android:layout_height="50dp" />
You are trying to implement android default color on a background which is not available that's why to give you an error message you can use below code for apply background color on TextView.
in xml :
android:background="#color/blue"
values
- color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="blue">#0000FF</color>
</resources>
You can define your color code in color.xml
I am trying to import a library in Android:
compile 'com.materialcontentoverflow:materialcontentoverflow:1.1.0'
But when I try it tells me that:
C:\Users\A\Desktop\Project\app\build\intermediates\exploded-aar\me.drakeet.materialdialog\library\1.2.2\res\values\values.xml
But if I look in that project there is no values with rippleColor. This is the file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- From: file:/Users/drakeet/AndroidStudioProjects/MaterialDialog/library/src/main/res/values/color.xml -->
<eat-comment/>
<color name="card_background">#ffffff</color>
<color name="card_shadow">#10000000</color>
<color name="lite_blue">#ff359ff2</color>
<color name="window_background">#00000000</color>
<!-- From: file:/Users/drakeet/AndroidStudioProjects/MaterialDialog/library/src/main/res/values/dimens.xml -->
<eat-comment/>
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- From: file:/Users/drakeet/AndroidStudioProjects/MaterialDialog/library/src/main/res/values/strings.xml -->
<eat-comment/>
<string name="action_settings">Settings</string>
<string name="app_name">MaterialDialog</string>
<string name="hello_world">Hello world!</string>
The library that I am trying to import has the following as values.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- From: file:/home/artur/workspaceAndroidStudio/MaterialContentOverflow/materialcontentoverflow/src/main/res/values/colors.xml -->
<eat-comment/>
<color name="shadow_end_color">#android:color/transparent</color>
<color name="shadow_mid_color">#14000000</color>
<color name="shadow_start_color">#44000000</color>
<declare-styleable name="FloatingActionButton"><attr name="android:background"/><attr name="backgroundTint"/><attr name="backgroundTintMode"/><attr format="color|reference" name="rippleColor"/><attr name="fabSize"><enum name="normal" value="0"/><enum name="mini" value="1"/></attr><attr name="elevation"/><attr format="dimension|reference" name="pressedTranslationZ"/></declare-styleable>
<declare-styleable name="MaterialContentOverflow"><attr format="reference" name="buttonDrawable"/><attr format="reference" name="fabButtonColor"/><attr format="reference" name="contentColor"/><attr format="enum" name="buttonPosition"><enum name="left" value="0"/><enum name="center" value="1"/><enum name="right" value="2"/></attr></declare-styleable>
<!-- From: file:/home/artur/workspaceAndroidStudio/MaterialContentOverflow/materialcontentoverflow/src/main/res/values/dimens.xml -->
<eat-comment/>
<dimen name="fab_content_size">24dp</dimen>
<dimen name="fab_elevation">8dp</dimen>
<dimen name="fab_size_mini">40dp</dimen>
<dimen name="fab_size_normal">56dp</dimen>
<dimen name="fab_translation_z_pressed">6dp</dimen>
I can't work out what the problem is?! Can anyone help please?
Checking the source on github
<!-- Ripple color for the FAB. -->
<attr name="rippleColor" format="color|reference" />
This library is using the rippleColor.
You can't use it since it is used by supportlibrary.
You can clone the library changing the attr.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Widget_demo</string>
<string name="action_settings">Settings</string>
<drawable />
</resources>
Here I am getting the following error in line <drawable />:
error: A 'name' attribute is required for `<drawable>`
Change
<string name="app_name">Widget_demo</string>
<string name="action_settings">Settings</string>
<drawable /> // remove this
to
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Widget_demo</string>
<string name="action_settings">Settings</string>
</resources>
Also go through the docs
http://developer.android.com/guide/topics/resources/string-resource.html
remove following:
<drawable />