0

I am trying to find a simple solution to adding an outline to text, to make it stand out no matter what background sits behind it.

A google search of this issue revealed very little. I was able to find one singular thread about this here: black line around the text

But the accepted solution is only part complete. I am not sure how to actually implement what Simon has suggested. I created the Java class he describes, but I have no idea how to actually use it.

Can anyone make sense of this, or have another way of achieving this?

This question has been marked as duplicate, but the answer linked does not work. Therefore, this is still an ongoing issue. The answer linked is the following:

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    Paint strokePaint = new Paint();
    strokePaint.setARGB(255, 0, 0, 0);
    strokePaint.setTextAlign(Paint.Align.CENTER);
    strokePaint.setTextSize(16);
    strokePaint.setTypeface(Typeface.DEFAULT_BOLD);
    strokePaint.setStyle(Paint.Style.STROKE);
    strokePaint.setStrokeWidth(2);

    Paint textPaint = new Paint();
    textPaint.setARGB(255, 255, 255, 255);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTextSize(16);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);

    Path path = new Path();
    String text = "Some Text";
    textPaint.getTextPath(text, 0, text.length(), 0, 100, path);
    canvas.drawPath(path, strokePaint);
    canvas.drawPath(path, textPaint);

    super.draw(canvas, mapView, shadow);
}

The line:

super.draw(canvas, mapView, shadow);

Is picked up by the compiler as an error. The .draw part is red, as it "cannot resolve method". Since this solution is not a working solution, this question is therefore not a duplicate.

Any further ideas on how to get this to work, anyone?

Community
  • 1
  • 1
Bisclavret
  • 1,327
  • 9
  • 37
  • 65
  • I usually just photoshop this, f your text is not likely to change or its just a few specific text. You can use a ImageView to put the image that you photoshopped. btw if you don't know how to use photoshop, just use the text tool and then Edit -> stroke – Sweeper Jul 30 '15 at 10:44
  • See also http://stackoverflow.com/questions/15091790/how-to-outline-a-textview, http://alexanderwong.me/post/39516673107/android-stroked-textview, https://android.googlesource.com/platform/packages/apps/Launcher2/+/tools_r22/src/com/android/launcher2/StrokedTextView.java, and other results for a Google search on `android textview outline`. "I created the Java class he describes, but I have no idea how to actually use it" -- since it is a subclass of `TextView`, you use it like a `TextView`. – CommonsWare Jul 30 '15 at 10:45
  • @Sweeper - It will be changing text mate. A score value that can move up and down. – Bisclavret Jul 30 '15 at 10:54
  • @CommonsWare - I tried to use it like a textview, in that I declared a myTextView in the same way I would declare a TextView in the xml layout. This resulted in the app crashing. – Bisclavret Jul 30 '15 at 10:56
  • @CommonsWare - Thanks for the links, I will give those a try when I am home later tonight. I am after a solid black line that surrounds the text, rather than a shadow, but I will try them anyway to be sure. – Bisclavret Jul 30 '15 at 10:58
  • "This resulted in the app crashing" -- then perhaps open a separate Stack Overflow question, where you show a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) along with the [Java stack trace for your crash](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this). – CommonsWare Jul 30 '15 at 11:01

0 Answers0