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);
Related
I am having a rather annoying scenario where I work with a lot of drawable shapes, many of which are slightly changed variants of others. The annoying thing is, when I paste the drawable, it automatically defaults to a random resource folder. See bellow photo. I want it to go directly to the standard drawable folder, not some other density drawable folders without having to manually change the folder every single time.
Is this even possible?
You can change the View from Android to Project if you are copying & pasting multiple images in a row. You can simply paste it to the drawable folder.
My ImageButton in my app is very tiny and cut off. I realized this could be because the image was in the drawable folder instead of the mitmap folders. So, I copied the images from the drawable folder, and pasted them in mitmap folders. Now, should I go about deleting the image from the drawable folder? I get the following saying it is not safe:
I know how to access the images, but should I delete them from the drawable folder now that I have already moved them to the mitmaps? If I do a delete anyway, will I need to alter my code to access the mitmap image? What is safest to do?
Here is an image of my mitmaps:
Thanks for the expert advice,
Rich
"Not safe" in this context just means that it's still being used somewhere. If you delete it, the current usage will fail to compile, and you'll be easily able to find and alter it to point at the new location.
You can safely delete this image, in Android Studio if you are using this image or else the file will be open at some place, you can get this error actually, so try deleting this image will safely remove the only selected image into your workspace. So hassle free to delete it.
After deleting your image, clear your project and run it, it works fine.
The mipmap folder is used for image that are very small and should be used in the action bar, and other menus. If you find your image too tiny, it just will be worst if you put it in the mipmap folder. If it's tiny although the image is in the drawable folder, maybe the image has a very small dimension or your imageview is too small.
I want to add my image in Drawable s All files according to its size with single image
how it can perform .
Actually I retrieve images from DB Server..While no need to define Server logic in your Answer
You can't add resources in your app at runtime. So you will not be able to add image in your drawables folder.
However you can store in it in a file in your app directory using Context.openFileOutput.
In my app, there may be more than thousand of small image/ icon
and they will be display in views inside the list view or grid view
While I am wondering how the data should be store
1. covert to the string array and store in the database.
2. in the drawable folder (and how should the path store in the database?)
3. other better method?
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon.
You should store the images in Drawable folder. The Drawable folder is pre-compiled. Which means that the images will be fetched much faster than from Database.
I want to set a specific background image for all my buttons.
So, I changed my PNG file into a Ninepatch drawable using the "draw9patch" tool(by specifying the line of strecth).
Then, I applied this as background to my button using
"myBtn.setBackgroundResource(R.drawable.new_png);"
Now, the background appears for the button, but the lines of stretch are also visible on the android screen, wherever I'd specified them in the tool.
Can you help? Is there something wrong in how I'm using the tool?
Ninepatch png files must be named with a special naming convention: for instance in your example, new_png.9.png. When you refer to the drawable in your code, you exclude the '.9.png', so your code would not need to change, only the image file name needs to change.