How to add single Image to all drawables from mainActivity programatically Android - android

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.

Related

How can i change fill color of a vector file fetched from server in android?

Is there anyway I can access the elements of vector file like fill color on the click of certain path fetched from the server. I am fetching whole vector file from the server. I have tried many library including RichPath ,VectorChildFinder, AndroidSVG but they require a vector file which is stored in res folder. It would not feasible to keep all the files in the res folder as there are many.
What I have achieved is I can parse it into a imageview but can't access the elements inside it.
Thank you.
I don't know about the others, but AndroidSVG does not require the file to be in a res or assets folder. The library doesn't include any method to fetch from a URL, but you can always fetch the file yourself and then use SVG.getFromString(fetchedSVGData).
If you don't want to handle the fetching yourself, you could use a library like Glide. It has an example of how to fetch SVGs and display with AndroidSVG.
To colour the SVG, just use AndroidSVGs ability to pass CSS stylesheet when rendering.

Android Performance: load images for listView

I'm going to develop an application which shows a ListView which each row have a seperate image (like personal picture for contacts list). It seems I have two options:
1- Store all images in Asset Folder and load image using setImageDrawable() command.
2- Store all images in Drawable Folder and load theme using setImageResource(R.drawable.xxx)
So my questions is does they differ in performance? And how can I speed up listView rendering such that images displayed in acceptable speed.
There should not much performance different to access image from Drawable or asset folder. You can see the answer too - > Android: Accessing images from assets/drawable folders
But, When you using ListView you are recreating the view . So, Where ever you store the image all the images are will not feel much different .
There are not so much differences. Just for coding pattern changes.
assets/
Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource.
drawable/
Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
https://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes

How to do it right : embedding a png directory to an android project and reffering to its items

what i did was that i added a directory named Images, which is full of png files to src\ (so all the images are in src\Images
and then reffered to it in code like this:
BitmapFactory.decodeFile("Images\\"+i+".png");
it didnt work, how can it be done correctly?
Add the images to the appropriate version of res/drawable-*/, based on density, then reference it a R.drawable.basename (for an image named basename.png) for places where you need them (e.g., setImageResource() on an ImageView).

How to set icon for a file?

I am creating different types of Files. For example File extension as.txt, .doc, .xml, .java, .jpg, .png, and etc. How to set the icon to be matched with the files. For example i am creating one pdf file. How to set pdf icon to that pdf file.
You dont have to explicitly set icons for the files, unless you are creating file with your own extension.
The operating system will understand the file type and binds the icon accordingly.
That is why in windows, if you manually change a file's extension, the icon changes automatically. Same case applies to Android also.
If you want to create different files via your android app & want to show the files list along with icon as we can see it in Windows OS, then you have to put all different images of each file extension in drawable folder. example- pdfImage.png, jpgImage.png, pngImage.png etc. Now you have to process the file name to determine the file extension runtime. then update your iconView (an ImageView item) like:
iconView.setImageBitmap(bitmap); // bitmap is the Bitmap image
or
iconView.setBackgroundResource(R.drawable.pdfImage_icon);

To create Nine patch drawable in Android?

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.

Categories

Resources