我一直在搜索但没有在Android应用程序中添加自定义图像作为表情符号的结果。感谢您提供任何帮助
这是我的问题:
我试图在android中做一个自定义键盘,只包括自定义图像作为表情符号,我设法在键盘中显示图像但是当我尝试发送它时,我得到[OBJ]作为回报。
以下是我的一些代码,我尝试了很多方法;
String s = "<img src='a.png'/>";
// Spanned cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.a) + "'/>", imageGetter, null);
/* ic.commitText( Html.fromHtml(s, new Html.ImageGetter() {
@Override public Drawable getDrawable(String source) {
Drawable drawFromPath;
int path =
emoji.this.getResources().getIdentifier(source, "drawable",
"com.cmosteknoloji.emoji");
drawFromPath = (Drawable) emoji.this.getResources().getDrawable(path);
drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(),
drawFromPath.getIntrinsicHeight());
return drawFromPath;
}
}, null),1);*/
Spanned spanned = Html.fromHtml(s, this, null);
ic.commitText(spanned,1);
@Override
public Drawable getDrawable(String arg0) {
// TODO Auto-generated method stub
int id = 0;
if(arg0.equals("a.png")){
id = R.drawable.a;
}
LevelListDrawable d = new LevelListDrawable();
Drawable empty = getResources().getDrawable(id);
d.addLevel(0, 0, empty);
d.setBounds(0, 0, empty.getIntrinsicWidth(), empty.getIntrinsicHeight());
return d;
}
ImageGetter imageGetter = new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
byte [] encodeByte=Base64.decode("iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",Base64.DEFAULT);
Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
Drawable d = new BitmapDrawable(bitmap);
Log.e("Chk", "Height : "+d.getIntrinsicHeight());
Log.e("Chk", "Width : " + d.getIntrinsicWidth());
return d;
}
};