Dean Blakely
Dean Blakely

Reputation: 3585

using an xml file as a drawable resource

I have an xml file named off.xml in my drawable directory (is should be a red circle)...

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<gradient android:startColor="#FFFF0000" android:endColor="#FFFF0000"
    android:angle="270"/>

On my main page I have the following xml...

<LinearLayout android:layout_width="match_parent"
    android:layout_height="50dip" android:orientation="horizontal">    
<View android:layout_width="40dip"
    android:layout_height="0dip"  android:layout_weight="1"
    android:background="@drawable/off" />
</LinearLayout>

I get the error "failed to convert @drawable/off into a drawable. The red circle does not show. (I have put a button there to make sure another widget would show)

What is causing this error. I got the example from another post in this forum that is supposed to work. thanks, Gary

Upvotes: 1

Views: 1738

Answers (3)

brillenheini
brillenheini

Reputation: 5453

Two problems: The closing </shape> tag is missing in your drawable and the layout_height of your view is 0 or has the wrong orientation.

Upvotes: 1

kumar_android
kumar_android

Reputation: 2263

your @drawable/off layout should be

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
  <item><shape android:shape="oval">
    <gradient android:startColor="#FFFF00" android:endColor="#FFFF00"
      android:angle="270"/>
    </shape></item>
</selector>

Upvotes: 1

dougcunha
dougcunha

Reputation: 1238

Try this:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >

    <gradient
        android:angle="270"
        android:endColor="#FFFF0000"
        android:startColor="#FFFF0000" />

</shape>

Upvotes: 1

Related Questions