0

Can someone tell me how to implement the color of border line (not the divider or separate line) of the RecyclerView?

I found that most of the posts have post the method to change color of the item separator line, but I can't find the method to change color of the outermost border, can someone help?

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
FrankieWong
  • 53
  • 1
  • 7
  • Can you post how you are using recycler view? Hint: It will have an item view layout. You can add the border there. – rushi Jul 05 '18 at 11:00
  • [Never tried] did you try to change background color? If not create a custom .xml file and create a share. change the border in shape. after that add that in the background. – Empty Brain Jul 05 '18 at 11:01

1 Answers1

0

You can't directly apply border to rcyclerView. You put a LinearLayout fitting the parent RecyclerView Layout and set the border to that LinearLayout.

Define the border_line.xml in drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="#F50057"/>
            <corners android:radius="5dp"/>
        </shape>
    </item>
</selector> 

And then apply it to child LinearLayout which is the child of RecyclerView like this:

 <android.support.v7.widget.CardView
                        xmlns:android="http://schemas.android.com/apk/res/android"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp">

                       <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@drawable/border_line"
                            android:orientation="vertical">
                      </LinearLayout>

    </android.support.v7.widget.CardView>

And you can change the border color in border_line.xml file.

Dinesh Neupane
  • 382
  • 10
  • 19
  • 1
    Thank you for trying to help, I found other solution which add border lines to the recyclerview directly or the parent view of recyclerview. https://stackoverflow.com/questions/1598119/is-there-an-easy-way-to-add-a-border-to-the-top-and-bottom-of-an-android-view – FrankieWong Jul 06 '18 at 03:54
  • 1
    @FrankieWong please note that TextView is not recyclerView. – Dinesh Neupane Jul 06 '18 at 04:50
  • @DineshNeupane and a link question not about textView :) and its work very well) – Fortran Jan 30 '21 at 15:29