Let’s set some value via layout XML to Custom View.

First, create values/attr.xml and define custom value. declare-styleable is the class name of Custom View. attr is the custom value.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomRecyclerView">
<attr name="leftSwipeColor" format="reference"/>
<attr name="leftSwipeIcon" format="reference"/>
<attr name="rightSwipeColor" format="reference"/>
<attr name="rightSwipeIcon" format="reference"/>
</declare-styleable>
</resources>

Second, use the custom value in layout xml.

<com.example.CustomRecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:leftSwipeColor="@color/left_swipe_color"
app:leftSwipeIcon="@drawable/ic_check_black_24dp"
app:rightSwipeColor="@color/right_swipe_color"
app:rightSwipeIcon="@drawable/ic_check_black_24dp" />

Then, get the value by TypedArray#getResourceId.

constructor(context: Context) : super(context) {
initialize(context, null)
}

constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
initialize(context, attrs)
}

constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
initialize(context, attrs)
}

private fun initialize(context: Context, attrs: AttributeSet?) {
val a = context.obtainStyledAttributes(attrs, R.styleable.EmptyRecyclerView, 0, 0)
val leftSwipeColor = a.getResourceId(R.styleable.EmptyRecyclerView_leftSwipeColor, 0)
val leftSwipeIcon = a.getResourceId(R.styleable.EmptyRecyclerView_leftSwipeIcon, 0)
val rightSwipeColor = a.getResourceId(R.styleable.EmptyRecyclerView_rightSwipeColor, 0)
val rightSwipeIcon = a.getResourceId(R.styleable.EmptyRecyclerView_rightSwipeIcon, 0)
a.recycle()
}

Now you can use custom value.