I have a TextView and I'd like to add a black border along its top and bottom borders. I tried adding android:drawableTop
and android:drawableBottom
to the TextView, but that only caused the entire view to become black.
<TextView
android:background="@android:color/green"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableTop="@android:color/black"
android:drawableBottom="@android:color/black"
android:text="la la la" />
Is there a way to easily add a top and bottom border to a View (in particular, a TextView) in Android?
My answers is based on @Emile version but I use transparent color instead of solid.
This example will draw a 2dp bottom border.
@color/bgcolor is the color of the background on wich you draw your view with border.
If you want to change the position of the border change the offset with one of:
or combine them to have 2 or more borders:
Just to add my solution to the list..
I wanted a semi transparent bottom border that extends past the original shape (So the semi-transparent border was outside the parent rectangle).
Which gives me;
Just as @Nic Hubbard said, there is a very easy way to add a border line.
You can change the height and background color to whatever you want.