您的位置:首页 > 其它

12.4

2015-12-04 12:40 218 查看
将表情添加到EditText

//表情点击事件,点击后显示在栏目中
gvFace.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
try {
// 获得资源ID的值,也就是静态变量的值
int resourceId = face[position];
// 根据资源ID获得资源图像的Bitmap对象
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
// 根据Bitmap对象创建ImageSpan对象
ImageSpan imageSpan = new ImageSpan(instance, bitmap);
// 创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像
SpannableString spannableString=null;
if (position>=10){
spannableString = new SpannableString("/f0"+position+1);
}else {
spannableString = new SpannableString("/f00"+position+1);
}
// 用ImageSpan对象替换face
spannableString.setSpan(imageSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// 将随机获得的图像追加到EditText控件的最后
editText.append(spannableString);
} catch (Exception e)
{
e.printStackTrace();
}
LogUtil.log(editText.getText());

}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: