Is it possible to load a drawable from the assets folder?

后端 未结 8 1675
刺人心
刺人心 2020-12-08 06:43

Can you load a drawable from a sub directory in the assets (not the drawable folder) folder?

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 07:04

    Here is function that does this for you.

    Check the returned Drawable variable for null as null may return if the path is invalid or there is an IOException.

    public static Drawable getDrawableFromAssetFolder(String fullPath, Activity ctx) {
        Drawable d =null;
        try {
            d = Drawable.createFromStream(ctx.getAssets().open(fullPath), null);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return d;
    }
    

提交回复
热议问题