This error shows up when I was writing my code. error:
Error: No resource found that matches the given name (at 'hint' with value '#string/edit_message').
The code is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
</LinearLayout>
That is easy.Just add a item like this in your res/values/strings.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="edit_message">YOUR MESSAGE TEXT</string>
</resources>
The default string resources folder android generates called strings, did you write the XML manually or it is a generated code?
if manually, try to fix it:
android:hint="#strings/edit_message"
Set hint on edittext like this from programmatically if resource is not found in your application:
editMessage.setHint("hint message"):
or you can simply
Call setHint() on the EditText.
Refer: http://developer.android.com/reference/android/widget/TextView.html#setHint%28int%29
Related
colors.xml is in the folder res/values/ which contains
<color name="offer_cell_price_bkg">#80000000</color>
But the android studio can not find it. I cleaned the project, relaunched the android studio and rebuilt the project, but still not work. Could you give me some suggestion? Thanks!
PS:I added my colors.xml file(It is a normal xml file, nothing special)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- item image -->
<color name="image_without_palette">#1C1D23</color>
<color name="text_without_palette">#ffeae1da</color>
</resources>
I tried to find other values like String and Dimen. I can find them.
The strange thing is: I can find colors in other xml like styles.xml. But can not find the colors in all fragment layout...
<LinearLayout
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:orientation="vertical">
<com.rey.material.widget.Slider
android:id="#+id/distance_range_slider"
style="#style/Material.Widget.Slider.Discrete"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:sl_primaryColor="#color/my_color_1"
app:sl_stepValue="1"
app:sl_textSize="0sp"
app:sl_value="20"/>
<com.easydinner.utils.Widgets.RalewaySemiBoldTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_bottom"
android:layout_marginTop="#dimen/margin_top"
android:gravity="center"
android:text="#string/services"
android:textColor="#color/my_color_2"
android:textSize="#dimen/font24"/>
</LinearLayout>
In the same fragment layout, I can find the color of namespace "app", but not the "android". For example, I can find "my_color_1", but not "my_color_2"
Really don't know the reason.
Change
xmlns:fab="http://schemas.android.com/tools"
to
xmlns:fab="http://schemas.android.com/apk/res-auto"
I resolved this problem by updating my android studio to version 1.5, and SDK platform tool to version 23.0.1.
The error says that for hardcoded you must use #string/.. what is wrong with just using "android:text= "price" ??
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:text="PRICE" />
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings:
String
XML resource that provides a single string.
String Array
XML resource that provides an array of strings.
Quantity Strings (Plurals)
XML resource that carries different strings for pluralization.
All strings are capable of applying some styling markup and formatting arguments.
for more information, read it here
Also it's better to use a string resource, that way if you have to change the text you change only one variable
So in your res folder there will be another folder called values, and then access the strings.xml file, inside that file you'll put a string resource to use in your app, like so:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">yourAppName</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="price">PRICE</string>
</resources>
and then in your xml file, you will change android:text="PRICE" to android:text = "#string/price"
Whenever am trying to change the background color by using
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#android:color/SomeColor">
Am getting the error:
Failed to parse file E:\ADT\sdk\platforms\android-18\data\res\color\SomeColor.xml
I have cleared the project and even restarted it several times but I have been unsuccessful in getting rid of the error.
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/SomeColor">
EDIT
And make sure that you set your color properly. You should set in strings.xml.
<color name="SomeColor">#ffff0000</color>
Or you can set
android:background="#dcdcdc" // give the appropriate color code here.
Hope this helps .. :)
now u fetch xml file itself dont do this dude just try to fetch color name itself in that xml like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="graycolor">#DCDCDC</color>
<color name="graycolor_press">#8B8B8B</color>
</resources>
Then fetch like this
<item android:drawable="#color/graycolor"/>
just started programming android and I am trying to make a simple xml file but it seems it got some problem with the android:text=#string/..
I have got this error:
error: Error: No resource found that matches the given name (at 'text'
with value '#string/ false_button').
For each of the strings..
The code is:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding= "24dp"
android:text="#string/question_text"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button"/>
</LinearLayout>
</LinearLayout>
You need to have the resources that you want to reference in your layout in strings.xml under res/values/
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="true_button">True Button</string>
<string name="false_button">False Button</string>
</resources>
#string/true_button refers to a resource in strings.xml
You can also have hardcoded string but not recommended
android:text="True Button"/>
add following to your string.xml file under values folder
<string name="true_button">true</string>
<string name="false_button">false</string>
Make sure that you are created string value with the name of false_button in the string.xml
<string name="false_button">false</string>
or just give name within the quotes "" in the android:text attribute
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="true_button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="false_button"/>
Click on res folder then click on values and then open strings.xml and add following content.
<string name="true_button">whatever text you want to write to your button</string>
<string name="false_button">whatever text you want to write to your button</string>
and save your file. Then clean your project by clicking Project -> clean and then run it again.
Hope this will help you.
make sure that in res/values/
you have all the resources present there as follows
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="true_button">True</string>
<string name="false_button">False</string>
</resources>
otherwisely you can hardcode values at yours layout where you specified button as
android:text="True "/> or android:text="False"/>
In your android project, look for the res directory. Open it and inside it look for values directory. In values, open strings.xml and check if it has a flase_button value stored in it . If not you can add a new value using name as false_button and value as what you want to display on the button.
When you open the strings.xml in IDE like eclipse, you can switch views of the .xml file by selecting proper tab given at the bottom of your eclipse screen. Select strings.xml view and
modify the current strings.xml to
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">app</string>
<string name="false_button">FALSE</string>
</resources>
Hope this was helpful.
You just need to add this in your Strings.xml class
just add <string name="false_button">False Button</string> line in your strings.xml
so that it will look like :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="false_button">False Button</string>
</resources>
All of these responses that refer to adding the string to the string.xml file make sense and work, but fail to address the original problem: this book ("Big Nerd Ranch: Android Programming") goes through these steps one at a time, mentions referencing the string in the layout XML file, but fails to mention adding to the strings.xml file. Fail.
I'm trying to set some general colors for a program I'm writing. I created a colors.xml file and am trying to directly reference the colors from the layout.xml file. I believe I'm am doing this correctly however it's giving me the following error:
Color value '#colors/text_color' must start with #
Here is my res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_color">#888888</color>
<color name="text_color">#00FFFF</color>
</resources>
Here is my res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:text="#string/hello"
android:layout_height="wrap_content"
android:id="#+id/TextView01"
android:textColor="#colors/text_color"/>
</LinearLayout>
I looked at some references on the android developers site: More Resource Types : Color and found this code:
Example:XML file saved at res/values/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="opaque_red">#f00</color>
<color name="translucent_red">#80ff0000</color>
</resources>
This application code retrieves the color resource:
Resources res = getResources();
int color = res.getColor(R.color.opaque_red);
This layout XML applies the color to an attribute:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/translucent_red"
android:text="Hello"/>
I think my two xml files follow this example pretty close - however the only difference is that I haven't used any application code to retrieve the color resource. I don't believe this is necessary (but it is a difference.) I thought I'd see if anyone else had similar problems or a solution? or is this a bug?
I did update all my android sdk (and Eclipse plugin) files last week so I believe them to be the latest.
A variation using just standard color code:
android:textColor="#ff0000"
After experimenting on that case:
android:textColor="#colors/text_color" is wrong since #color is not filename dependant. You can name your resource file foobar.xml, it doesn't matter but if you have defined some colors in it you can access them using #color/some_color.
Update:
file location:
res/values/colors.xml
The filename is arbitrary. The element's name will be used as the resource ID. (Source)
You have a typo in your xml; it should be:
android:textColor="#color/text_color"
that's "#color" without the 's'.
You should write textcolor in xml as
android:textColor="#color/text_color"
or
android:textColor="#FFFFFF"