android – add border at bottom of TextView element

How can I add a border at the bottom of the TextView in Android. The following is the XML code of my TextView.

    <?xml version="1.0" encoding="utf-8"?>     <TextView xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="20sp"         android:text="Sales"         android:textColor="#000"         android:gravity="center"         android:padding="10dp"        /> 

and I am calling the XML like,

ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mContext,                        R.layout.layoutName, lables); 

How to add the border below each content.

enter image description here

Any help is really appreciated.

Add Comment
3 Answer(s)

After using Suraj’s code, since I am using the array adaptor, I faced a new error “ Array adaptor requires the resource id to be a text view ". I fixed the error with the help of the following reference link.

"ArrayAdapter requires the resource ID to be a TextView" xml problems.

Here is my java code,

ArrayAdapter<String>dataAdapter =  new ArrayAdapter<String>(mContext, R.layout.home_callus_selection,R.id.text, lables); 

and the XML code

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical">      <RelativeLayout         android:id="@+id/opening_today_layout"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="horizontal"         android:gravity="center"         >         <ImageView             android:id="@+id/iv"             android:layout_width="25dp"             android:layout_height="25dp"             android:paddingLeft="8dp"             android:layout_centerVertical="true"              android:src="@drawable/callred" />         <TextView             android:id="@+id/text"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:ellipsize="end"             android:layout_centerVertical="true"             android:layout_toRightOf="@+id/iv"             android:textSize="20sp"             android:textColor="#000"             android:padding="10dp"             android:text="Sales" />       </RelativeLayout>     <View         android:layout_width="match_parent"         android:layout_height="1dp"         android:background="#C1BFBF"         />   </LinearLayout> 
Add Comment

If you are using recyclerview you can use DividerItemDecoration.

add below code:

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.HORIZONTAL);

recyclerView.addItemDecoration(dividerItemDecoration);

Answered on July 17, 2020.
Add Comment

You can put a view below your textview like this:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical">      <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textSize="20sp"         android:text="Sales"         android:textColor="#000"         android:gravity="center"         android:padding="10dp"        />      <View         android:layout_width="match_parent"         android:layout_height="1dp"         android:background="@color/colorPrimary"        />  </LinearLayout> 
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.