7

i want to make the white coloured text in my android app have a black outline. I do not want to colour the textview so if that is your help then no i already know how to do this. I want to make this happen by using a drawable file in xml format. so is there away i can outline the edges of my text in xml?

user2357673
  • 89
  • 1
  • 1
  • 6

1 Answers1

16

One way is to use shadow:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFF"
    android:shadowColor="#000000"
    android:shadowDx="0.0"
    android:shadowDy="0.0"
    android:shadowRadius="2.0" />

This gives white text a black outline. Adjust the radius accordingly to how thick you'd like it.

Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • this does not work at all when i put it in xml the text is just white – user2357673 Jun 27 '13 at 13:34
  • what device are you testing on? Try changing the radius to something bigger. Here's how it looks for me: http://i.stack.imgur.com/9gdSs.png – Ken Wolf Jun 27 '13 at 13:44
  • 2
    yes it works but the black is blurry is there nothing to make the black a solid colour – user2357673 Jun 27 '13 at 14:39
  • like this link http://catlikecoding.com/unity/documentation/text-shaders/text-smooth-outline-foo.png – user2357673 Jun 27 '13 at 14:40
  • Have you considered using a custom font? http://www.fontspace.com/category/outline – Ken Wolf Jun 27 '13 at 14:43
  • do you know how to use a font style downloaded from fontspace. if so can you let me know how to import it and use it in xml – user2357673 Jun 28 '13 at 09:05
  • You have to do it in code. Basically you download it, put it in your /assets/ directory, then in code you `.setTypeface()` on your `TextView`. There are some tutorials online: http://vimaltuts.com/android-tutorial-for-beginners/android-custom-font-example – Ken Wolf Jun 28 '13 at 09:15
  • it's very useful. tanx – Amintabar Nov 13 '14 at 13:31