I'm trying to add an image to menu item programmatically using glide.
main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_profile_pic"
android:icon="@mipmap/profile_pic"
android:orderInCategory="100"
android:title=""
app:showAsAction="always" />
Java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.mipmap.profile_pic);
requestOptions.error(R.mipmap.profile_pic);
MenuItem itemProfilePic = menu.getItem(0);
//View view = findViewById(R.id.action_profile_pic);
if (savedProfilePic != null) {
Glide.with(this)
.setDefaultRequestOptions(requestOptions)
.load(Uri.parse(savedProfilePic))
.into(itemProfilePic);
}
return true;
However, I can't use this approach since the resource is a MenuItem and not an ImageView. Casting it to an ImageView also doesn't work.
How can I achieve the desired result, given that the image is not in the drawables folder, its set by the user, hence below approach also can't be used:
itemProfilePic.setActionView(savedProfilePic);
Takes in an integer value
Final result