Can't access res/drawable in xml file - android

I am creating a loading screen using animation-list but I've run into a error where I cannot get access to my res/drawable folders inside my xml file. The error I get is "No resource found that matches the given name (at 'drawable' with value '#drawable/loadingwave0.png')"
Inside the directory res/anim/ My xml code is simple:
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="#drawable/loadingwave0.png"
android:duration="100" />
</animation-list>
I've noticed that inside my item tag, Eclipse does not predict any drawable resources even though I've already copied them(not referenced) to the drawable folders(hdpi, ldpi, mdpi). My .png images can be accessed through my AndroidManifest.xml file if I use the code
<item android:icon="#drawable/loadingwave0.png"/>
for making sure the drawable folders can be accessed. I have already cleaned and refreshed my project multiple times.
Any help would be greatly appreciated.

you should use :
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="#drawable/loadingwave0"
android:duration="100" />
</animation-list>
the resource id is the file name without extension.

Related

How to use animation-list in android studio

I am developing an app in which i want to use frame animation. for this i am using animation-list. I am using android studio in which i created an anim folder inside the res folder.now i m not able to add any item. studio does not showing any tag like item when i pressed ctrl + space.
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
</animation-list>
You don't need to create anim folder. You have to paste the images and resource xmls in drawable folder. If you do not have drawable folder then create one inside of your res folder.
I have pasted 4 png images and a spin_animation.xml file inside of the drawable folder.
spin_animation.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/selected" android:oneshot="false">
<item android:drawable="#drawable/ani4" android:duration="500" />
<item android:drawable="#drawable/ani3" android:duration="500" />
<item android:drawable="#drawable/ani2" android:duration="500" />
<item android:drawable="#drawable/ani1" android:duration="500" />
</animation-list>
Suppose you want to replace a imageView
ImageView gyroView = (ImageView) findViewById(R.id.gyro);
to show animation. Set the background of that imageView
gyroView.setBackgroundResource(R.drawable.spin_animation);
Create an Animation Drawable object based on this background:
AnimationDrawable gyroAnimation = (AnimationDrawable) gyroView.getBackground();
Start the animation:
gyroAnimation.start();
For detail help check this.
in Android Studio, put the xml file in the res/drawable/ directory of your Module.
See these google offical doc below:
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
http://developer.android.com/guide/topics/graphics/drawable-animation.html

I have a error while creating an item in my menu?

<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/test"
android:icon="#drawable/ic_lanucherxx.png" // error
android:title="#string/news"
android:showAsAction="ifRoom"/>
<item android:id="#+id/test2"
android:icon="#drawable/we.png" //error
android:title="#string/newss2"
android:showAsAction="ifRoom"/>
here is the xml file . the error says that there are no such images in the drawable folder . But i have made sure that that required images are present in all of those drawables folders .
Thank you for your time .
don't use extension .png
just remove it and try once i hope it solves your problem

rollover android

I want to make a rollover with android.
I saw that it is necesarry to write a XML 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/verde" />
<item android:drawable="#drawable/rojo" />
</selector>
I saved it with the name button.xml.
I don't know in which folder save it.
Then I tried to used the reference in my layout.xml
I change the background attribute for my button in my layout.xml from
android:background="#drawable/red"
and use the
android:background="#drawable/button"
Save button.xml in the folder res/drawable if it's applicable for all screen sizes/devices, otherwise put it in the folder with the appropriate qualifier suffix (e.g. drawable-hdpi, drawable-ldpi etc).
See here (http://developer.android.com) for a full example, and explanation of other states you could include.

XML resource file not getting copied in Android

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

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.

Categories

Resources