Issue
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.
Solution
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.
Answered By - Alexei Andronov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.