视图组可见或消失也可以理解,它不需要对话框。每次初始化情感时,我总是使用像 [happy]=R.drawable.happy 这样的键值。这是情感的文本,而内容像 [快乐]
public SpannableString textToImage(String content,Context c){
SpannableString ss = new SpannableString(content);
int starts = 0;
int end = 0;
if(content.indexOf("[", starts) != -1 && content.indexOf("]", end) != -1){
starts = content.indexOf("[", starts);
end = content.indexOf("]", end);
SharedPreferences shared=c.getSharedPreferences("emotion",0);
int resource=shared.getInt(content,0);
try {
Drawable drawable =c.getResources().getDrawable(resource);
if (drawable != null) {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, starts,end + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} catch (Exception ex){
}
}
return ss;
}