下面是我的HomeActivity.java代码。我在操作栏上添加了两个菜单。我想要的是我想在actionProfile项目中设置用户个人资料。我在谷歌搜索了很多,但找不到与我的问题相关的任何解决方案。我通过我的网络服务使用凌空获取用户个人资料网址,我想在操作栏菜单中设置用户图像。我怎样才能做到这一点?
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;
}
}