Programmatic (Solution):
If you just want to change the color for the dividers instead of creating a custom drawable you can use a ColorDrawable:
DividerItemDecoration itemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
itemDecoration.setDrawable(new ColorDrawable(R.color.greycc));
recyclerView.addItemDecoration(itemDecoration);
If the size matters in addition to colors you can use a GradientDrawable:
DividerItemDecoration itemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[]{0xfff7f7f7, 0xfff7f7f7});
drawable.setSize(1,1);
itemDecoration.setDrawable(drawable);
recyclerView.addItemDecoration(itemDecoration);
Note that setting the color values in the array requires a full octet of hex values, otherwise incorrect colors will be shown i.e., 0xFF3E3E3E as opposed to 0X3E3E3E.
Colored Dividers Update (2023):
val itemDecoration = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
itemDecoration.setDrawable(
ResourcesCompat.getDrawable(resources, android.R.color.holo_green_light, theme)!!
)
recyclerView.addItemDecoration(itemDecoration)