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);
Related
I know i can use my own svg as icons by browsing them from the asset studio but it just show the name not the exact icon of the svg, i can't know just by name what that icon is look like , so can i view them while adding them to project like they are showing in below image?
I have many icon on my computer can i add them to that list , so that i can see them visually when i want to add a new vector asset.
I tend to think that it can be done because then icons which android asset studio is shows must be stored in a directory from where it pulls when when i open asset stdio , if i can add my svg to that directory then android studio may may also pull them too with default clip arts and they may also show up in asset studio, does anyone know what that directory is , or any other way of doing this.
Note android studio does not give such option via UI
When you add a new vector asset (assuming you've added it in the drawable directory), it gets added in the drawable directory.
It is generally saved by the name ic_thatSVGname. So it gets the prefix IC. So please browse in the drawable directory and you will find your vector asset.
Then double click on it so that it opens and you can see the preview on right side of the screen. It it doesn't, just click the PREVIEW button which also reside on the right side of the Android Studio.
So that means just search for that in drawable directory. And while adding new vector assets, right click on the DRAWABLE DIRECTORY only so that it gets into that directory else it might end up outside it.
in Delphi, I add image resources to the project (via project > resources and Images), however i need for one java function to give a resource ID in the application's package of the drawable to use. Is it possible to retrieve a resource ID (integer) from my delphi resource file or name ?
If not, how in delphi we can add a custom resource image and retrieve it's resource ID ?
Getting a Resource ID
To retrieve the resource ID of a resource:
id := TAndroidHelper.GetResourceID('my_image', 'drawable');
If you are using an older version of Delphi you may need to use the alternate, older approach:
id := TAndroidHelper.Context.getResources.getIdentifier(StringToJString('my_image'), StringToJString('drawable'), TAndroidHelper.Context.getPackageName);
The shorter, more recent (and convenient) GetResourceID function is merely a wrapper around the earlier longer winded version.
In either case, my_image is the filename (without extension) of the image resource whose ID you need.
The drawable parameter tells the helper that it is a drawable resource ID that you are asking for (as opposed to a string or layout, for example).
Adding Image Resources
To add a custom image resource to your project use the Deployment option of the Project menu in the IDE.
Add your file and set the remote path to a suitable drawable resource folder, e.g.:
res\drawable
res\drawable-xxhdpi
etc
You could put your own scaled versions of the image in each drawable folder for different resolutions. The remote_name must be the same in each case. The specific drawable folder determines the applicable device resolution.
Alternatively you could simply provide one suitably high resolution file. You can place this in either an appropriate high-resolution folder (e.g. drawable-xxxhdpi) or simply in drawable.
Either way, Android will auto-scale the images at runtime for other device resolutions as necessary.
There are lots of Android references on the subject of drawable scaling, alternative versions for different display types etc, including the Android documentation itself of course.
Referencing your comment, there are however no XML files required for adding drawables that are straightforward images.
Additional XML may be necessary for other types of drawable resources, but that will very much depend on the nature of your specific needs.
Bringing It All Together
In the screenshot below the highlighted entry is one that I have added for a PNG image resource. The file is in my project folder so there is no local path (the first column).
The filename is appstore.png and I have configured the deployment to place one copy of that file in the res\drawable' folder of the application when it is deployed (theremote` folder).
This file will rely on auto-scaling for display on different resolutions devices.
To get the resource ID of that resource I then simply write:
id := TAndroidHelper.GetResourceID('appstore', 'drawable');
I have a png file named triedsohardicon.png I want to use for my app's launcher icon, but after putting it in the folder associated with the project, I find that Image Asset Studio doesn't show any triedsohardicon.png in its file system browser in that location.
In addition, if I put the line
android:icon="#drawable/triedsohardicon"
in AndroidManifest.xml (because I did in fact put the png file in the TriedSoHard/app/src/main/res/drawable folder), the text in quotes just returns the error "Cannot resolve symbol '#drawable/triedsohardicon'".
The png has dimensions 512x512. I could use some help, please.
Launcher Icon should be placed in mipmap res\mipmap\triedsohardicon.png
Place your launcher Icon through Image Asset like below:
Upload and Save the png and it will be placed in mipmap automatically.
In Maifest:
android:icon="#mipmap/triedsohardicon"
Hope this helps.
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.
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