I have this code:
android:drawable="#pickuptools.png"
the picture is called pickuptools.png and is inside the folder drawable-xhdpi.
I have tried #drawable-xhdpi/pickuptools.png, pickuptools without the file extension, and many more.
I can't find the picture through the XML.
The XML is located inside the drawable-xhdpi folder.
What am I doing wrong?
Use:
android:drawable="#drawable/picuptools"
You don't need to use #drawable-xhdpi or something. For any resources , you should use resource type(In your case its drawable) and name of the resource.
For further reference, check out this Android page on how to access Resources.
Related
basically i have created a folder insde the Drawable Folder called "logo" with a image at different scales, i have seen in different tutorials that you can just reference the folder in the atributte "src" and thats it, you can totally use the view normally, but for some reason i cant do that in here.
i have tried changing the name of the folder but i still have the same problem, plus if i just drop the images inside the drawable folder, i can use them normally...
Thanks for your help !
enter image description here
When put images on drawable v24 app crashes , and use the same image
in drawable work correctly.
Look at which line your app is crashing in Logcat. You will be calling the resource file like this: R.drawable.yourresource. In this case it will work fine. If you change this line to R.drawableV24.yourresource and place the resource file in drawable V24 folder, it will work.
It all depends on how you identify the resource file :)
Please check your image drawable folder if the image in drawableV24 so transfer it in an only drawable folder and check it
Image resources placed in the res/drawable/ directory may be automatically optimized with lossless image compression by the aapt tool during the build process.
for more detail click here
I'm looking to have a user select an image from the gallery, and have this file saved as a permanent drawable resource when they open the app at a later time. Is this possible?
I mean as an object in the actual drawable folder.
No, it's not possible. "The drawable folder" doesn't exist as a file system folder at runtime - it's part of your (read-only) binary .apk file.
You could instead save the image at internal folder and/or define a preference string.
Check this old answer https://stackoverflow.com/a/3374138/4618976
On my application I have many pictures which I have grouped in folder under res/drawable. But Android dosen't let me access them trough "R". Is there a way to access those folders.
This is the Code im using for.
ImageView iv = new ImageView(conext);
iv.setImageResource(R.drawable.**smiley.666**);
I marked the part which I can't access.
Thx in Advance
safari
No, Android does not allow subfolders under /res/drawable: Can the Android drawable directory contain subdirectories?
You can however, add all image files under /drawable and then access them programmatically via:
int drawableID = context.getResources().getIdentifier("drawableName", "drawable", getPackageName());
iv.setImageResource(drawableID);
Where drawableName is a name of the drawable file, i.e. myimage if image file is myimage.jpg.
The code above will get image resource with id R.drawable.drawableName.
R.drawable.xxx is just a reference that the Android SDK generates in your R.java file. You are trying to make a sub-folder in your res-folder. The SDK can't generate a reference to any of your sub-folders, you have to put it in the predefined folders drawable-hdpi, -ldpi and -mdpi.
If you dont know how this works. I'll sum up. Android runs on a lot of different devices with a lot of different screen resolutions. With these three folders, you can have the same picture in three resolutions and depending on the device you are running your app on, one of these three folders will be used. You can read more here:
http://developer.android.com/guide/practices/screens_support.html
You can't create folders in res/drawable the system doesn't recognize those.
you need to save your image first and then make a xml for them so you can access it through R.your_pics
context.getResources().getDrawable(R.drawable.progressbar1);
Android - Open resource from #drawable String
I am new to Android development. To implement a photo gallery app, tutorial said to add images to res/drawable and access them via R.drawable.image1 .. etc. But there is no drawable folder default in eclipse, then I created a one and add images. But cannot access images, there is no option in R.drawable. as "image1"
Any idea ?
you should create "drawable" folder under "res", and you'd best place png image files in that folder. When accessing these image files programmingly.set an image for an ImageView for example:
Drawable imgDrawable=getResources().getDrawable(R.drawable.yourImageFileName));
imgView.setImageDrawable(imgDrawable);
Sometimes the drawable folder is not created by default Instead it will have "drawable-hdpi","drawable-mdpi" and "drawable-ldpi".These folders are for placing images for various screen densities to support different resolutions.Your "drawable folder" is for baseline medium density.
In your case create a folder named "drawable" under "res" and place your image inside that folder and you will be able to access it using R.id.imagename .Try refreshing the project and check whether you have created the drawable folder under the res folder.Also check the case of the folder name that you have created.
I faced same problem , but when i added those images again in jpg format it worked.
Might work for you too.
My System was based on windows 10 & was using android studio 4