我正在嘗試爲我的android應用創建自定義視圖。在OnDraw
函數中,我試圖通過使用其unicode
值來繪製表情符號,但這似乎不起作用。以下是代碼:使用unicode值在Android畫布上繪製表情符號
public class Scale extends View {
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final static int LINE_WIDTH = 10;
...
...
@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(LINE_WIDTH);
mPaint.setColor(Color.BLUE);
...
...
//This works
canvas.drawText("My text", 0.05f*width, 0.80f*height, mPaint);
//But this does NOT draw a doughnut!!
String s = new String(Character.toChars(0x1F369)); //Doughnut
canvas.drawText(s, 0.75f*width, 0.50f*height, mPaint);
}
}
任何人都知道是否有任何解決方法在這裏?或者我做錯了什麼?
EDIT [第二個問題]:隨着我下面提出的黑客,我看到了表情符號都在Canvas
繪製TextView
內呈現,但他們是顯著相比,表情符號,在正常的TextView設置暗淡 ,如下圖所示:
任何想法,我缺少什麼嗎?
由於,但這似乎沒有幫助: 'String s = new String(Character.toChars(0xD83C))+ new String(Character.toChars(0xDF69)); // Donut canvas.drawText(s,0.75f * width,0.50f * height,mPaint);' – Curious