Html.ImageGetter

前端 未结 4 1246
暖寄归人
暖寄归人 2020-11-29 03:32

Can any one help me out how to use Html.ImageGetter to dispaly images using html image src tag ? and example or good tutorial

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 04:28

    Here is the same as the accepted answer, but as a top level class (which is nicer if you want to use it from different places):

    public class ResourceImageGetter implements ImageGetter {
        private Context mContext;
    
        public ResourceImageGetter(Context context) {
            mContext = context;
        }
    
        @Override
        public Drawable getDrawable(String source) {
            Resources resources = mContext.getResources();
            int identifier = resources.getIdentifier(source, "drawable", mContext.getPackageName());
            Drawable res = resources.getDrawable(identifier);
            res.setBounds(0, 0, res.getIntrinsicWidth(), res.getIntrinsicHeight());
            return res;
        }
    }
    

提交回复
热议问题