开发者

Unable to resolve drawable in attribute "src"

I'm having a problem when trying to load various images to an image button using an xml file in the drawable-mdpi folder. It worked for one button but doesn't work for the other. The code works for the second image button but not the first, I get the error,

" main.xml: Unable to resolve drawable "C:...workspace\AndroidAlarm\res\drawable-mdpi\keyEntry.xml" in attribute "src".

I did the exact same thing in the first imageButton that I did for the second. The xml file for the second button (working one) looks like:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true"
       android:drawable="@drawable/events_pressed" /> <!-- pressed -->
 <item android:drawable="@drawable/events" /> <!-- default -->
</selector>

and for the one that doesn't work, it looks like:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true"
       android:drawable="@drawable/key_entry_pressed" /> <!-- pressed -->
 <item android:drawable="@drawable/key_entry" /> <!-- default -->
 </selector>

The only difference between the two is the images being passed in. 开发者_运维百科All the images are found in the drawabl-mdpi folder. I can't figure out why it works for the second image button but not the first. the xml code for the two buttons looks like:

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
            <ImageButton
                android:id="@+id/imagebutton1"
                android:src="@drawable/keyEntry"
                android:background = "@android:color/transparent"               
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:scaleType = "fitXY"
                android:layout_marginTop = "50px"
                android:layout_marginLeft = "40px"
                android:layout_marginRight = "20px"
                android:layout_marginBottom = "50px"
                android:layout_weight="1"/>
            <ImageButton 
                android:layout_marginTop="50px"
                android:layout_width="wrap_content"
                android:layout_marginRight="40px"
                android:id="@+id/imagebutton2"
                android:layout_weight="1" 
                android:src="@drawable/events" 
                android:layout_height="wrap_content" 
                android:background="@android:color/transparent" 
                android:layout_marginLeft="20px" 
                android:layout_marginBottom="50px" 
                android:scaleType="fitXY">
             </ImageButton>
         </LinearLayout>  

Thanks in advance!


Resources can not contain capital letters:

    android:src="@drawable/keyEntry"

You should have error complaining about resource name:

    Invalid file name: must contain only [a-z0-9_.]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜