java - How to set Icon in Action bar menu item? -


below homeactivity.java code. have added 2 menu on action bar. want want set user profile in actionprofile item. have search lot on google not found solution related problem. getting user profile url through web service using volley , want set user image in action bar menu. how can achieve ?

home_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/actionprofile"         android:orderincategory="100"         app:showasaction="ifroom"         android:icon="@drawable/profile"         android:title="edit profile">     </item>      <item         android:id="@+id/actionlogout"         android:orderincategory="100"         app:showasaction="ifroom"         android:icon="@drawable/logout"         android:title="logout"/> </menu> 

homeactivity.java

public class homeactivity extends appcompatactivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_home);      }       @override     public boolean oncreateoptionsmenu(menu menu) {         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.home_menu, menu);         menuitem item = menu.finditem(r.id.actionprofile);         if (item != null) {             item.seticon(r.drawable.profile);         }         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         switch (item.getitemid()) {             case r.id.actionprofile:                 intent intent = new intent(homeactivity.this, profileactivity.class);                 startactivity(intent);                 break;             case r.id.actionlogout:                 logoutuser();                 break;             default:                 break;         }         return true;     } } 


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -