Essential Android RecyclerView edit forum

Add divider lines to RecyclerView items

Just add these lines to the initialization

RecyclerView mRecyclerView = (RecyclerView) view.findViewById(recyclerView);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));

Add an adapter and call .notifyDataSetChanged(); as usual ! This is not an inbuilt feature of Recyclerview but added in the support libraries. So don’t forget to include this in your app level build.gradle file

compile ""
compile ""
Multiple ItemDecorations can be added to a single RecyclerView.

Changing divider color :

It’s pretty easy to set an color for a itemDecoration.

  1. step is: creating a divider.xml file which is located on drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android=""
    <solid android:color="@color/divider_color"/>
  1. step is: setting drawable
// Get drawable object
Drawable mDivider = ContextCompat.getDrawable(m_jContext, R.drawable.divider);
// Create a DividerItemDecoration whose orientation is Horizontal
DividerItemDecoration hItemDecoration = new DividerItemDecoration(m_jContext,
// Set the drawable on it
// Create a DividerItemDecoration whose orientation is vertical
DividerItemDecoration vItemDecoration = new DividerItemDecoration(m_jContext,
// Set the drawable on it

Table Of Contents
22 RecyclerView
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close