I wanted to Display Calendar Icon as a Button In Android. I have created a Image Button as,
ImageButton DtPk = new ImageButton(this);
I know that image will set as,
Drawable d = Drawable.createFromPath("#drawable/calendar");
DtPk.setBackgroundDrawable(d);
But where do i store image in my project? And how.
When the project was created you should see a folder called "res" and inside it several different drawable folders. Place the image inside of the one called drawable-mdpi. Then simple do the following:
DtPk.setImageResource(R.drawable.calendar);
Here is another SO post explaining more about drawable folders: Drawable folders in res folder?
And read the section called Bitmap File in this document: http://developer.android.com/guide/topics/resources/drawable-resource.html
Related
When I paste an image or icon into the folder drawable Default choices do not appear Like : xxhdpi,xhdpi,hdpi or mdpi look at the picture :
I used the same method in previous times but Now these choices do not appear His method was very easy through selections xxhdpi,xhdpi,hdpi or mdpi in popup window But now what will I do?
I want to import the same icon But in different sizes , It is inside the drawable folder .
I want to show me such a list
You need to create all required folder manually.
like hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi etc and then after that options appear.
If u have all folder types(drawable hdpi,drawable mdpi,drawable xhdpi,drawable xxhdpi,drawable xxxhdpi), just copy these folders, in res\ by right click on res folder and just paste, then android studio update drawable folder to new changes.
When I add an image into the drawable folder, the image shows in text format although the image name is in lowercase.
I tried all the drawable folders, but the error still doesn't go away.
Create a new folder inside res, name it drawable.
Move birthday.jpg to drawable folder.
in xml, set attribute android:background="#drawable/birthday" to your imageView/layout in which you want your image to be displayed.
How can I populate the image switcher dynamically, when I have the images in the drawable folder and sub folder .. like drawable-ldpi/S_001/a001_001.jpg.
I have tried to populate one image, but the application crashed.
Here is the code:
ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
imageSwitcher.setImageDrawable(getResources().getDrawable(getResources().getIdentifier("S_001/a001_001.jpg", "drawable", getPackageName())));
I need some assisstance.
drawables folder is for img resources used by your app, like icons, 9-patches, backgrounds and other ui elements. You can't put subdirectories there.
If you plan to use some photos in an ImageSwitcher or anything like this, you should use assets folder. Read this to find out more.
Is there a way to draw store an application icon in a drawable folder?
I would like to display the application icon next to the application name in a list view.
I know there is a method to get the icon but I am not too sure how to store that icon so I can use it at a later time.
The application icon should already be stored in a drawable folder (in fact best practice is to have one stored in every density drawable folder)
You should be able to reference it at runtime just like anyother drawable using R.drawable.ic_launcher or whatever name you gave the file if it wasn't ic_launcher
so to put it into an ImageView you could do something like
iv.setImageResource(R.drawable.ic_launcher);
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