How To Outline A Textview?
Solution 1:
1) create your textview object extends TextView
publicclassYourTextViewextendsTextView { .........
2) Do this on its draw method
@Overridepublicvoiddraw(Canvas canvas) {
for (inti=0; i < 5; i++) {
super.draw(canvas);
}
}
3) set textview's xml side as below
android:shadowColor="@color/white"android:shadowRadius="5"
Solution 2:
I found simple way to outline view without inheritance from TextView. I had wrote simple library that use Android's Spannable for outlining text. This solution gives possibility to outline only part of text.
Library: OutlineSpan
Class (you can copy only class):OutlineSpan
Solution 3:
Couldn't this this but try experimenting with: PorterDuff.Mode
http://developer.android.com/reference/android/graphics/PorterDuff.Mode.html
Try changing it to 'ADD' or 'CLEAR', hope this helps.
Solution 4:
You need to change your getWhiteBorderPaint() method to the following:
privatestatic Paint getWhiteBorderPaint(){
Paint p = new Paint();
p.setColor(Color.WHITE);
return p;
}
The Paint constructor only takes bitmasked flags and doesn't support arbitrary ints as parameters.
Solution 5:
Investigated into the original problem stated by this question. Found the solution.
First, change DST_OUT to DARKEN
static {
BLACK_BORDER_PAINT.setXfermode(newPorterDuffXfermode(PorterDuff.Mode.DARKEN));
}
Secondly, save the original text color, and put the intended outline color up, draw the outline, and then restore the original text color.
@Overridepublicvoiddraw(Canvas aCanvas) {
intoriginalColor=this.getCurrentTextColor();
this.setTextColor(0xff000000); //set it to white.
aCanvas.saveLayer(null, borderPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
| Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG);
drawBackground(aCanvas, -BORDER_WIDTH, -BORDER_WIDTH);
drawBackground(aCanvas, BORDER_WIDTH + BORDER_WIDTH, 0);
drawBackground(aCanvas, 0, BORDER_WIDTH + BORDER_WIDTH);
drawBackground(aCanvas, -BORDER_WIDTH - BORDER_WIDTH, 0);
this.setTextColor(originalColor);
aCanvas.restore();
super.draw(aCanvas);
}
Post a Comment for "How To Outline A Textview?"