The attribute is not declared (Android) on basic xml attributes

后端 未结 3 1654
灰色年华
灰色年华 2020-12-14 07:48

I\'m new to this Android development, and I find the layout of it really confusing. I\'m trying to have a background image on a view, and I\'ve tried using this example Add

相关标签:
3条回答
  • 2020-12-14 08:05

    Problem

    Intellisense could not pick the attributes we type although those attributes are existing in android SDK and shows this Attribute is not declared.

    Solution

    I got this problem yesterday in Visual Studio 2015 and started searching about this, ultimately I found that these two files are missing in XML schema folder in Visual Studio, so download these files links given below,

    1. https://github.com/atsushieno/monodroid-schema-gen/blob/master/android-layout-xml.xsd
    2. https://github.com/atsushieno/monodroid-schema-gen/blob/master/schemas.android.com.apk.res.android.xsd

    Just download and move files manually to C:\Program Files (x86)\Microsoft Visual Studio 14.0\Xml\Schemas or simply just add these schemas within Visual Studio. This error will be gone, I resolved this issue with this procedure.

    0 讨论(0)
  • 2020-12-14 08:06

    Create a template-based Xamarin.Android app.

    Taking the vector.xml example from the Google/Android VectorDrawable docs and creating that as a .xml file under the Resources/drawable directory in the project:

    <?xml version="1.0" encoding="UTF-8" ?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
         android:height="64dp"
         android:width="64dp"
         android:viewportHeight="600"
         android:viewportWidth="600" >
         <group
             android:name="rotationGroup"
             android:pivotX="300.0"
             android:pivotY="300.0"
             android:rotation="45.0" >
             <path
                 android:name="v"
                 android:fillColor="#000000"
                 android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
         </group>
     </vector>
    

    Update your Resouce/layout/Main.axml to include the vector on the background of the LinearLayout and the Button:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
            android:background="@drawable/vector"
            >
        <Button
            android:id="@+id/myButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello"
            android:background="@drawable/vector"
            />
    </LinearLayout>
    

    Results in:

    Not a pretty example from Google, but it works.

    Cleaning up your vector and setting the color to red

    <?xml version="1.0" encoding="UTF-8" ?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
         android:height="256dp"
         android:width="256dp"
         android:viewportHeight="60"
         android:viewportWidth="60" >
         <group
             android:name="rotationGroup"
             android:pivotX="0.0"
             android:pivotY="0.0"
             android:rotation="0.0" >
            <path
                android:name="so"
                android:fillColor="#F44336"
                android:pathData="M20.5,9.5
                  c-1.955,0,-3.83,1.268,-4.5,3
                  c-0.67,-1.732,-2.547,-3,-4.5,-3
                  C8.957,9.5,7,11.432,7,14
                  c0,3.53,3.793,6.257,9,11.5
                  c5.207,-5.242,9,-7.97,9,-11.5
                  C25,11.432,23.043,9.5,20.5,9.5z" />
         </group>
     </vector>
    

    Results in:

    0 讨论(0)
  • 2020-12-14 08:10

    As I know, those attributes (that you pointed out above) aren't defined in jdk_1.7.

    Use jdk_1.8 instead.

    You can configure the path to the JDK in the following way:

    Microsoft Visual Studio 2015 -> Tools -> Options -> Xamarin -> Android Settings -> JDK Location [Change]

    Remark

    If you are using Microsoft Visual Studio 2015 Update 3 or one of the earlier versions, I assure you that the warning won't disappear... this is already the Intellisense's issue (not the JDK's). It has to be fixed in the future release.

    0 讨论(0)
提交回复
热议问题