如何在Android中获取相应的文件图标? [英] How to get corresponding file icon in Android?

查看:61
本文介绍了如何在Android中获取相应的文件图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与每种文件的特定图标相关联的文件类型.

现在,如果我选择 somefilename.xxx ,那么我如何能够选择与 *.xxx 相关联的图标,而不是未知文件的默认图标./p>

原始问题

如何获取 .txt .doc .png 文件图标?例如,现在我选择 filename.pdf ,如何获取 filename.pdf 图标?例如

  File f = new File("filename.pdf"); 

我的文件名是 filename.pdf .如何获取此文件图标(Adobereader图标).

解决方案

第一件事,我想说任何文件通常都不包含图标,说如果您不要没有办公室已安装您将不会获得文档图标或PowerPoint图标.

因此它的系统可以将图标与特定文件类型相关联,因此请按这种方式

为实现您的目标,强烈建议您包含预期使用的所有图标说出如果您选择 some.png 进行扩展检查并将 png.ico 与此文件图标相关联

这样做,您将不得不与每种类型的文件相关联.

您可以轻松地在网络上找到图标,然后将其添加到可绘制文件夹的每个文件名中,提取扩展名并根据扩展名设置图标这样,您就可以实现自己的目标

要实现您的目标,请执行以下操作:

  1. 将所有图标文件添加到您的res \ drawable文件夹中,以方便设置所有图标文件名称作为其扩展名说 doc.png 用于 doc扩展 为方便起见

  2. 现在将所有文件扩展名映射到您的图标文件,说检查文件扩展,然后执行以下操作:

String ext =东西";

 开关(ext){案例"doc":image.setImageResource(R.drawable.doc);休息;案例"exe":image.setImageResource(R.drawable.exe);休息;默认 :image.setImageResource(R.drawable.default);} 

Every file type associated with its specific icon.

Now if i am choosing somefilename.xxx then how i could be able to choose the icon associated with *.xxx rather than the default icon for unknown file.

Original Question

How can I get .txt or .doc or .png file icon? For example now I am choosing filename.pdf, how to get filename.pdf icon? For example

File f = new File("filename.pdf");

My File name is filename.pdf. How to get this file icon (Adobereader Icon).

解决方案

First thing i would like to say any file do not contains it icon with them in general say if you don't have office installed you won't get doc icon or powerpoint icon.

so its system work to associate icon to specific file type so Go this way

To achieve your goal its highly recommended to include all icons that you are expected to use say if You choose some.png check for extention and associate the png.ico to this file icon

doing this way you will have to associate with every type of files.

Edit 1:

you can easily find out the icons on web add to it into your drawable folder's now for every file name extract the extension and set the icon according to the extension this way you can achieve your goal

Edit 2 :

To achieve your goal do the following :

  1. add all icon files to your res\drawable folder for easyness set all icon file name as its extension Say use doc.png for doc extension for easyness

  2. Now map all file extension to your icon file say check for file extension and then do something like following:

String ext = "Something";

switch(ext)    
{    
case "doc":    
    image.setImageResource(R.drawable.doc);    
    break;     
case "exe":    
    image.setImageResource(R.drawable.exe);
    break;
default :
    image.setImageResource(R.drawable.default);    
}

这篇关于如何在Android中获取相应的文件图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆