android drawable invalid start tag - android

I'm trying to set a tabhost selector, as i found an example demonstrating that i should create an xml file in drawable like this :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/hotel_selected"
android:state_selected="true" />
<item android:drawable="#drawable/hotel" />
</selector>
but when compiling, eclipse keep saying that it's an invalid start tag in this file.
please help me solve this.
many thanks.

Found a solution, I created the xml file by using a simple text editor (notepad++) and saved it to /res/drawable and compiled, result: it worked like a charm :)

Ideal solution should be to put the XML file in
/res/xml

i have came across the same error and than solved, i did mistake of adding the xml file under values folder so it was not able to recognise selector tag. i removed it from values folder and added inside the drawable folder and it worked without any error. this was in case of Xamarin.Android.

You can right click on the directory you want to create the XML file, selecect Android xml file, and then edit that file. This solved my issue.

Its seems that there is no any error.
There may be some problem. But you can do one thing, do Project -> Clean , it may resolve your issue.

Related

Trying to make a ToggleButton with images, getting error: <item> tag requires a 'drawable' attribute or child tag defining a drawable

I am trying to follow a simple tutorial online about making a toggle button in android with images (so it shows images instad of ON/OFF).
It doesn't work. The error I get is
- Binary XML file line #1: <item> tag requires a 'drawable' attribute or child tag defining a drawable
I am using Visual Studio 2019 and coding with Xamarin.
I have a toggle button defined like this in my activity_main.xml:
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/toggleButton1"
android:background="#drawable/toggleButton_emp"
android:id="#+id/toggleButtonEmp"/>
Then I have a "toggleButton_emp.xml" file in "Resources\drawable" which contains:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/faction4" android:state_checked="true"/>
<item android:drawable="#drawable/faction3" android:state_checked="false" />
</selector>
faction4 and faction3 are valid drawables I have added to "Resources\drawable"
I have found many answers for this issue that are most 10 years old, and none help. They often say to make "drawable" first tag but it's already first. Or removing spaces but I don't have any.
Okay so in this case it turned out the problem was that apparently either Android or Visual Studio does not accept .svg format (I assume the former). But there is no error message (format not supported?), no notice, nothing. So I assumed at this day an age, it should either accept it or barf in some way.
The error message I got was also not indicative of real problem in any way. It said that there is no drawable tag, while there clearly was one. So there was no way to guess drawable itself is the culprit.
Anyways, replacing ".svg"s with ".png"s fixed the issue.

Selector does not work with mipmap image in android

All I want is that an imagebutton which changes to another image when user press the button on. Following is my directory list. As you see I don't have drawable-hdpi, drawable-mdpi ..and others. And also I can't see mipmap-hdpi, mipmap-mdpi ..and others. My problem is I can't add selector xml for my imagebutton.
directory list
Following image is my content_main file which known as activity_main.
content_main.
My program shows the image of button but when I add android:background="#drawable/fbpressed" code piece in content_main, the program fails. it says unfortunately Login2 has stopped!
I tried lots of combination for my selector file which is fbpress.xml. like I tried android:icon="#mipmap/facebook_pressed" but it fails again and again. any idea?
Please change you selector:
<selector>
<item android:drawable="#mipmap/facebook_press" android:state_press="true">
<item android:drawable= "#mipmap/fracebook">
</selector>
Please click the Android in you screenshot , and change it to Project.It can be more clear.
Yes guys I've solved the problem. I did not know that i should change my values/styles.xml file if i add an resource file into my button. (which is fbpress.xml)
Also I changed my folder representation from Android style to Project style so that i can see my mipmap-hdpi, mdpi etc.
change from android to project
I add those lines into my styles.xml. fbpress is my resource file which is selector file.
<style name="fbpressed" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/fbpressed</item>
</style>
Following is my part of content_main.xml. I added android:background="#drawable:fbpressed" and style="#style/fbpressed" lines into this file.
imageButton
And finally my button works =) Thanks for all your helps

Strange Lint Warning - Unexpected text found in layout file: ""

I've got the following selector defined in button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/button_settlement_background_pressed" />
<item android:state_enabled="true"
android:drawable="#drawable/button_settlement_background_normal" />
<item android:state_enabled="false"
android:drawable="#drawable/button_settlement_background_disabled" />
</selector>
When I run lint I get the following warning: Unexpected text found in layout file: "". It says it's happening at line 4 in "drawable". All of the referenced drawables exist in /res/drawable.
Does anyone know what could be causing this? I can ignore the warning but I'd rather fix it if possible.
Also, I get warnings for unused strings and icons when they're only referenced in AndroidManifest.xml. Is there a way to fix those instead of ignoring them?
Using Project>Clean.
Fixed that problem in my case.
Perhaps there's an invisible character somewhere in the white space. I'd try recreating the xml from scratch (not using copy-and-paste, which would just copy the problem, if that's what's happening). I'd also clean and rebuild the project.
As far as the unused resource warnings, I don't think there's a way to control this. The problem of false positives is hugely worse for library projects. Android lint is a fairly new tool and (in my opinion) still has a lot of rough edges.
You can also Format the xml file (CTRL + SHIFT + F). The extra characters would be displayed.
typically, this would happen when you inserting something like "android:id=" without a newline and using eclipse's auto completion, like this:
<LinearLayout
android:id= >
^
here type enter, the code would appears to be like this:
<LinearLayout
android:id="#+id/
the character '>' has been erased and '"' become invisible.
use ctrl+shift+f to format the file to find the hidden characters.
I found that if I closed the file I had the hidden character on, then reopened the same file. The character was no longer hidden (and typically was just after the />, for example />" ).
Analyze -> Inspect code
It worked for me!
In XML file, tags contain attributes. consider the line: (last ">" should not be there) ...
<selector xmlns:android="http://schemas.android.com/apk/res/android">
Make sure that the tag on first line does not contain">".
Replace above code with:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
...
</selector>
Now other elements are under selector tag. I hope this helps.

layout-xxx/ causing TypeClass file collision: A resource exists with a different case: '....R$ID.class'

Everything is working fine with my Android project with the standard layout, however whenever I add a new layout-xxx subdirectory, say layout-large, and copy an XML file to it to be my baseline for the new size in question, from that point forward I get the error listed above and the project won't compile.
Location TypeClass file collision: A resource exists with a different case: 'R$ID.class'
If I remove the xml file from the layout-xxx directory everything goes back to working fine. I do have the support-screen tags in the manifest.
I can't possibly need to ID all my views and such inside my layout with seperate names for seperate layout files do I? This would make coding so rediculously conditional that it would not be worth it.
What am I doing wrong? or missing?
I had the same issue today and it was because of my mistake.
I had my menu defined like this
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_item_share_action_provider_action_bar"
android:showAsAction="always"
android:title="#string/action_bar_share_with">
<menu >
<item android:id="#+Id/someid"
android:title="MyMenu"/>
</menu>
</item>
</menu>
Reason of error was Id with capitalized I which should be actually like id
Hope this helps someone

Style / themes not working

whenever I try to apply a VERY simple style in eclipse I get errors:
the style is as below (filename styles.xml in res/layout)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="commonStyle">
<item name="android:background">#EEEEEE</item>
</style>
</resources>
Regardless of whether I try to apply this to a LinearLayout (using style="#style/commonStyle") or to an activity in my manifest file (using android:theme="#style/commonStyle") I ALWAYS get the error "No resource found that matches the given name...".
If I try to apply an Android theme to an activity (say Theme.Black) it works just fine.
If I remove any usage of my style, my R.java file is generated as normal with the following contents:
public static final int styles=0x7f030002; (in the generated layout class)
I have NO idea what is going on. It seems that NOONE is having the same troubles as me (Ive spent about 4 hours searching using google, and came up with not even a remotely close answer).
Ive tried restarting eclipse, clean building etc. etc. and nothing works what so ever...
So what am I missing?
Try moving your styles.xml file to res/values.
http://developer.android.com/guide/topics/resources/style-resource.html
Styles need to be stored in the res/values folder :)
http://developer.android.com/guide/topics/ui/themes.html (See Defining Styles)
The name of the XML file is arbitrary,
but it must use the .xml extension and
be saved in the res/values/ folder.
I haven't used styles in my code yet, however generally you need to use
android:
Does it work when you use this?:
<style android:name="commonStyle">
Please verify the you call the style in the correct manner :
for example this might compile but will not work :
style="mainButtonText"
this is the correct way to call style:
style="#style/mainButtonText"

Categories

Resources