Create the drawable and pass the drawable id to the function. For example, I create a vector drawable called arrow_back.xml
.
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:autoMirrored="true">
<path
android:pathData="M20,11L7.8,11l5.6,-5.6L12,4l-8,8l8,8l1.4,-1.4L7.8,13L20,13L20,11z"
android:fillColor="#fff"/>
</vector>
Note: the drawable that homeAsUpIndicatorId
is referencing has a
private modifier, so you can't access it directly. However, the above
code was copied from the vector drawable with little modification.
I will pass the id to the getDrawable()
function like this.
ContextCompat.getDrawable(context, R.drawable.arrow_back);
EDIT:
Do the following to get the drawable from homeAsUpIndicatorId
:
TypedArray a = getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {R.attr.homeAsUpIndicator});
int attributeResourceId = a.getResourceId(0, 0);
ContextCompat.getDrawable(context, attributeResourceId);
a.recycle()