Unable to enable selection in src attribute

I had a problem loading various images onto an image button using an xml file in the drawable-mdpi folder. It worked for one button, but did not work for another. The code works for the second button of the image, but not the first one, I get an error message: "main.xml: could not resolve the selection" C: ... workspace \ AndroidAlarm \ res \ drawable-mdpi \ keyEntry.xml "in the attribute" src ". I did the same in the first image that I did for the second. The xml file for the second button (working) looks like this:

<?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 this:

 <?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 image transfer. All images are in the drawabl-mdpi folder. I cannot understand why it works for the second button of the image, but not for the first. The xml code for the two buttons looks like this:

  <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!

+4
source share
1 answer

Resources cannot contain capital letters:

  android:src="@drawable/keyEntry" 

You should have an error associated with the resource name:

  Invalid file name: must contain only [a-z0-9_.] 
+1
source

Source: https://habr.com/ru/post/1341188/


All Articles