0

I can't find a way to put a stroke on text (on the text, not on the whole text view box) , the stroke should be around the letters. is there any custom text view or library or drawing can be implemented to draw a stroke

        <TextView
            style="@style/Header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="150dp"
            android:text="HELLO DROID"
            />

i expect the text to look like so , (the stroke color is red) enter image description here

  • Do you mean a strikethrough text? If yes, this question is your answer: https://stackoverflow.com/questions/3881553/is-there-an-easy-way-to-strike-through-text-in-an-app-widget – gpunto Nov 29 '19 at 21:12
  • @gpunto thank you, but no that's not what I'm looking for, the stroke should be around the letters. – Anas Alhayek Nov 30 '19 at 19:01
  • Do you please add screenshots of your expected output and actual output? – Android Geek Dec 04 '19 at 05:07

1 Answers1

2

I tried below two ways for adding stroke to text :

First is add shadow to your TextView:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="50sp"
        android:textColor="@android:color/holo_blue_light"
        android:text="Hello"
        android:shadowRadius="10"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowColor="@android:color/holo_red_dark"/>

The output of above code is: enter image description here

Second I found GitHub project android-outline-textview. Please follow this Link

For this you need to add StrokedTextView and related files to your project after that add below Code in XML file:

 <com.skd.stackdemo.StrokedTextView
        android:id="@+id/stroke"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="60sp"
        android:text="Hello"
        android:textColor="@android:color/holo_blue_light"
        android:layout_marginTop="30dp"/>

Add below code in Java file:

StrokedTextView stroke = findViewById(R.id.stroke);
stroke.setStrokeColor(Color.RED);
stroke.setStrokeWidth(1f);

The output of above code is: enter image description here

I hope it works for you.

Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • 1
    I would highly recommend _not_ using that library. It calls `setTextColor()` in `onDraw()`, which invalidates the `TextView`, and causes an infinite redraw loop. Just FYI. – Mike M. Dec 10 '19 at 22:50