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 a background image to shape in xml Android, but it looks very bad (bitmaps you know)
So I thought vectors could be fun. Only problem is that I cannot get even the official examples to work. I've tried setting this as a background
<?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="256dp" android:width="256dp" android:viewportWidth="32" android:viewportHeight="32"> <path android:fillColor="#8fff" 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" />
It renders in the design view and all, but the attributes viewportWidth
, viewportHeight
, fillColor
and pathData
all show the same warning:
The 'http://schemas.android.com/apk/res/android:viewportWidth' is not declared
If I check the file, sure enough, it's not there. Does that mean I have to explicitly declare all those types? It seems a bit odd for vanilla examples.
Note that if I remove the 'android' in front of the warnings, it will remove warnings but still give me the same deployment error
Android.Views.InflateException: Binary XML file line #1: Error inflating class <unknown>
tools:showIn This attribute allows you to point to a layout that uses this layout as an include, so you can preview (and edit) this file as it appears while embedded in its parent layout.
Xmlns means xml namespace. It is created to avoid naming conflicts in the xml's. In order to avoid naming conflicts by any other way we need to provide each element with a prefix. Now android here simply means we are assigning the namespace “http://schemas.android.com/apk/res/android” to it.
Tools attributes reference. Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources).
Attribute is missing the Android namespace prefix This error is related to one of the XML files in your Android Workspace Project, Reason ? You have missed out xmlns namespace attribute in one of your XML: AndroidManifest.xml, layout.xml, or any Custom XML that you have added.
Note: These attributes don't work for ListView in Android Studio 2.2, but this is fixed in 2.3 ( issue 215172 ). Intended for: Any root <View> in a layout that's referred to by an <include>
Design-time view attributes Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources).
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,
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With