[mono-android] XML Drawable Resource as background won't compile

Jonathan Pobst monkey at jpobst.com
Wed Mar 9 23:53:29 EST 2011


Despite the fact we do some magic to allow you to have mixed case 
filenames, Android requires all lowercase and it all gets converted to 
that in the background.

Therefore, you have to reference your background all lowercase:

android:background="@drawable/shapedrawabledemo"

Jonathan


On 3/9/2011 9:53 PM, Nathan Blevins wrote:
> Hey all,
>
> I have an odd issue that I am hoping is due to the fact that I do not
> have enough caffiene in my system.  Bascially, I am trying to define a
> shape drawable via XML and set it as the background to a layout element.
>   Here is my drawable syntax located within a file called
> ShapeDrawableDemo.xml within the Drawable directory:
>
> <?xml  version="1.0"  encoding="utf-8"  ?>
> <shape  xmlns:android="http://schemas.android.com/apk/res/android">
> 	<gradient  android:angle="180"  android:startColor="#FFFFFF"  android:endColor="#000000"/>
> </shape>
>
> Now, I have modified my main.axml file to use this drawable as a
> background like this:
>
>
> <?xml  version="1.0"  encoding="utf-8"?>
> <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
> 		android:orientation="vertical"
> 		android:layout_width="fill_parent"
> 		android:layout_height="fill_parent"
> 		>
> 	<Button  android:id="@+id/MyImage"
> 		android:layout_width="fill_parent"
> 		android:layout_height="wrap_content"
> 		android:background="@drawable/ShapeDrawableDemo"
> 		android:text="Testing"/>
> </LinearLayout>
>
> For some reason, I am getting a build error that says:
>
> Error3No resource found that matches the given name (at 'background'
> with value '@drawable/ShapeDrawableDemo').G:\Projects\Monodroid
> Book\Graphics_Drawables\Graphics_Drawables\Resources\Layout\Main.axml14Graphics_Drawables
>
> If I use this drawable via code-behind, it works perfectly.
>
> Console.WriteLine(Resource.Drawable.ShapeDrawableDemo.ToString() +"  - This works and has an ID!");
>
> Here is my autogenned R file:
>
> public  partial  class  Drawable
> {
> 	
> 	// aapt resource value: 0x7f020000
> 	public  const  int  Icon = 2130837504;
> 	
> 	// aapt resource value: 0x7f020001
> 	public  const  int  ShapeDrawableDemo = 2130837505;
> 			
> 	private  Drawable()
> 	{
> 	}
> }
>
>
> Any suggestions?  Am I somehow futzing up the syntax somewhere?  Thanks,
>
> Nathan
>
>
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid



More information about the Monodroid mailing list