Loading...

Adding Border to the Top and Bottom of an Android View

Android provides us a lot of components to make fast and professional application. TextView, ImageView etc are the common and important components in android. In this tutorial, you will learn to add a border to the top and bottom of an android view.

Border to the android views can be added with different ways. Here, I am going to show the simplest and easiest way to add border to the android views (TextView, Button).

For adding border you have to create an XML drawable file inside res/drawable directory and this is worked in android 2.2 and higher.

Related:
How to Add Border to Android ImageView
How to Set Android Button and TextView Border Color
Android Button Styles Example

Android Example: How to Add Border to the Top and Bottom of an Android View


Following are the XML file of drawable and XML layout file.

XML Drawable File


First we have to create an XML drawable file border_top_bottom.xml in /res/drawable folder like /res/drawable/border_top_bottom.xml and link it to TextView. Your drawable XML file will look like this.

res/drawable/border_top_bottom.xml

XML Layout File


Following is the content of XML layout file where I have added a TextView.

res/layout/top_bottom_border_in_android_view.xml

Strings.xml File


res/values/strings.xml

Android Example: How to Add Border to the Top and Bottom of an Android View

Now, run your Adding Border to the Top and Bottom of an Android View application, you will see the border at the top and bottom of TextView.
XML 7227411559309026983
Home item