How to get corresponding file icon in Android?

后端 未结 3 1001
有刺的猬
有刺的猬 2021-02-10 16:57

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 as

3条回答
  •  情书的邮戳
    2021-02-10 17:27

    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);    
    }
    

提交回复
热议问题