I have the below XML in slider_button.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="#android:drawable/button9patch" />
...
</selector>
The android:drawable="#android:drawable/button9patch" gets the error:
Error: No resource found that matches the given name (at 'drawable'
with value '#android:drawable/button9patch').
However I think I have the file in the right place (I've even put it in all the drawable folders to be sure):
What am I doing wrong? Thanks
change like this
android:drawable="#drawable/button9patch"
Related
I'm developing an android project, and I want to use a <selector> in an XML file. I've put the <selector> in a file under res/drawable/default_item_background_selector.xml, and I'm referencing it with XML attributes like
<TextView
android:background="#drawable/default_item_background_selector"/>
The XML attribute content I get from Eclipse's content assist, so that can see it just fine. However, when I compile everything (and it compiles just fine) and debug it on either simulator or on a device, the app crashes, with a root exception of :
09-24 23:55:14.771: E/AndroidRuntime(22478): Caused by:
android.content.res.Resources$NotFoundException: File
res/drawable/default_item_background_selector.xml from drawable
resource ID #0x7f020000
The R.drawable.default_item_background_selector gets generated just fine, but at runtime, it appears there's no physical file generated in the output directory. Has anybody experienced this before ? Yes, I've cleaned and recompiled (so many times).
Created default_bg.xml in Drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="true"
android:drawable="#drawable/red" />
<item android:state_pressed="true" android:state_selected="false"
android:drawable="#drawable/blue" />
<item android:state_selected="false"
android:drawable="#drawable/yellow" />
</selector>
Create drawables in **strings.xml** is
<drawable name="blue">#0000FF</drawable>
<drawable name="red">#FF0000</drawable>
<drawable name="yellow">#FFFF55</drawable>
And set background to textview
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:background="#drawable/default_bg"
/>
Resources$NotFoundException: File res/color/dark.xml from drawable resource
I have that error. I tried clean project. I can see "dark" in "R" file. I can use it in project: I mean autocomplete working well, but when I turn on app on emulator there is this error. There is how I use it:
songList.setSelector(R.color.dark);
The correct way to use setSelector() is:
Create a xml in res/drawable
For example, let res/drawable/selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="#color/black" />
</selector>
Then declare black in your res\values\strings.xml
<color name="black">#000000</color>
Then set selector as
songList.setSelector( R.drawable.selector);
Note: Answer ideas taken from this post.
EDIT:
Try cleaning your project in Eclipse and re-starting Eclipse.
You're putting your drawable resource in the res/color folder. You should be putting that in the res/drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ff0000"/>
<item android:state_focused="true"
android:color="#0000ff"/>
<item android:color="#00ff00"/>
</selector>
I have this selector which I'm trying to use to change the background of a Linearlayout. Whenever I try to apply it, however I always get this error message:
org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: tag requires a 'drawable' attribute or child tag defining a drawable
Obviously, it want me to use the drawable attibute but I'm not sure how to do that and change the background like I want to.
android:drawable="#color/red"
and add this in every item with diffrent color....
I have this menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/refresh" android:title="Actualizar" android:icon="#android:drawable/ic_menu_refresh"></item>
<item android:title="Sair" android:id="#+id/exit" android:icon="#android:drawable/ic_menu_close_clear_cancel"></item></menu>
and i'm getting this error:
Error: Resource is not public. (at 'icon' with value '#android:drawable/ic_menu_refresh').
Why the resource is not public? I have this icon in other apps and worked.
Maybe it's protected. In some API level, some icons are allowed to use, some are not. You can try ic_menu_home ic_menu_preferences ic_menu_help
Some links to refer:
http://groups.google.com/group/android-developers/browse_thread/thread/dabbe62aa1b54c13
android: resource not found
I am having problems with nine patch images ( **.9.png ). I have a widget layout and would like to use nine patch images for the widget's backgroud. Here is my background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/appwidget_bg" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/appwidget_bg" />
<item android:state_focused="true" android:drawable="#drawable/appwidget_bg" />
<item android:state_focused="false" android:drawable="#drawable/appwidget_bg" />
</selector>
The drawbales name is "appwidget_bg.9.png". This stuff works fine. But I would like to use different images for the focused and pressed states.
So I make it look like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/appwidget_bg_pressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/appwidget_bg_pressed" />
<item android:state_focused="true" android:drawable="#drawable/appwidget_bg_pressed" />
<item android:state_focused="false" android:drawable="#drawable/appwidget_bg" />
</selector>
The problem: As soon as I add the additional drawable "appwidget_bg_pressed.9.png" I get the following error message:
.../res/drawable/widget_bg.xml:21: ERROR Error: No resource found that matches the given name (at 'drawable' with value '#drawable/appwidget_bg').
.../AndroidManifest.xml:6: ERROR Error: No resource found that matches the given name (at 'icon' with value '#drawable/icon').
It seems like I can only add one nine patch drawable to the drawables folder. Why is that?
Are you certain they've been imported into your drawables folder? That error is saying it's not found the files. You can certainly have multiple 9-patch images. Seems like it's found appwidget_bg_pressed.9.png, but isn't seeing just appwidget_bg.9.png or icon.png
This is an old question, but I was facing same problem and I figured it out and solved my problem.
The problem was with 9-patch drawables; they had patches on one side instead of two. because I didn't want my drawable to stretch vertically but it seems that I can't do it with one side patching.
I hope it'll help others.