Element must be declared error for tag shape

AndroidGradle

Android Problem Overview


I'm using Android Studio I/O(Preview) 0.3.2

I'm using this example to define background gradient in my app. I get Element must be declared error. enter image description here

I've checked and I'm not find any solutions. Can anyone help me how can I declare that tag in the xml

Android Solutions


Solution 1 - Android

This problem was caused by my xml file. My gradient XML file was in the values folder, I solved this problem by moving gradient file to drawable folder

Solution 2 - Android

You could just right click

> res

and hit

> New

, to create a

> Android Resource File

, and choose

> Resource Type

to be

> Drawable

, and change whatever the default

> root element

to

> shape

Yeah it's kinda buggy in Android Studio to create a new XML file other than layout and values lol.

hope it can help you!!

Solution 3 - Android

I had the same problem with Android Studio , I created a directory "anim" under "res" then copied the xml file to that one then the error gone.

Solution 4 - Android

You need to use selector inside <set/> tags like that;

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_enabled="true" android:state_pressed="true">
            <objectAnimator
                android:duration="@android:integer/config_shortAnimTime"
                android:propertyName="translationZ"
                android:valueTo="15dp"
                android:valueType="floatType" />
        </item>
        <item>
            <objectAnimator
                android:duration="@android:integer/config_shortAnimTime"
                android:propertyName="translationZ"
                android:valueTo="5dp"
                android:valueType="floatType" />
        </item>
    </selector>
</set>

Solution 5 - Android

Had a similar problem with the selector tag used to create a state list animator.

My animation was in the anim resource folder. Had to move it to the animator folder.

Solution 6 - Android

Looking at that example, I think if you add the xmlns:android attribute (inside the shape tag, as in the example that you are following), it will work:

xmlns:android="http://schemas.android.com/apk/res/android"

I suspect that shape is declared there.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSimon MokheleView Question on Stackoverflow
Solution 1 - AndroidSimon MokheleView Answer on Stackoverflow
Solution 2 - AndroidRobotCharlieView Answer on Stackoverflow
Solution 3 - AndroidAbakasha PandaView Answer on Stackoverflow
Solution 4 - AndroidDiRiNoiDView Answer on Stackoverflow
Solution 5 - AndroidJonView Answer on Stackoverflow
Solution 6 - AndroidjcwView Answer on Stackoverflow