Issue
I am searching for default drawable of back arrow. In this question showed how to get it in xml. But I am searching for using in programming side (java/kotlin).
I want to use this drawable id in code like:
ContextCompat.getDrawable(context, homeAsUpIndicatorId);
Solution
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()
Answered By - devmike01
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.