2014-10-30 29 views
1

如何使用特定的TextAppearance繪製文本?繪製具有特定文本外觀的文本

這是我的代碼。

Paint paint = new Paint(); 
    paint.setAntiAlias(true); 
    paint.setColor(Color.WHITE); 
    paint.setFakeBoldText(false); 
    paint.setTextSize(textSize); 
    // TODO: set the style of the text to a specific TextAppearance. E.g. @android:style/TextAppearance.DeviceDefault.Large.Inverse 
    canvas.drawText(context.getResources().getString(R.string.myString), textOffsetX, textOffsetY, paint); 

我已經看過TypeFace對象,但我不知道如何從TextAppearance創建字樣。

回答

2

的同事,給了我一個使用TextView作爲TextAppearance

TextView textView = new TextView(context); 
textView.setTextAppearance(context, android.R.style.TextAppearance.DeviceDefault.Large); 
paint.setColor(textView.getCurrentTextColor()); 
paint.setTextSize(textView.getTextSize()); 
paint.setTypeface(textView.getTypeface()); 
的一座橋的解決方案