android textview 显示表情和文字 表情带超链接

public int getResourceId(String name){
        try {
            //根据资源的id的变量名获得field对象。使用反射来实现的
            Field field = R.drawable.class.getField(name);
            //取得并返回资源的id的字段。
            System.out.println(Integer.parseInt(field.get(null).toString()));
            return Integer.parseInt(field.get(null).toString());


        } catch (Exception e) {
            // TODO: handle exception
        }
        return 0;
    }
String html = "图像";

        CharSequence charSequence = Html.fromHtml(html,new ImageGetter() {

            @Override
            public Drawable getDrawable(String arg0) {
                Drawable drawable = getResources().getDrawable(getResourceId(arg0));
                if(arg0.equals("image")){
                    drawable.setBounds(0,0,drawable.getIntrinsicWidth()/2,drawable.getIntrinsicHeight()/2);

                }
                return drawable;
            }
        },null);
        textView.setText(charSequence);
        textView.setMovementMethod(LinkMovementMethod.getInstance());

你可能感兴趣的:(android)