アイコンをツールバーに追加する場合に使用します。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Notification Found -->
<item android:id="@+id/action_notify_found"
android:icon="@drawable/about"
android:title="About"
app:showAsAction="ifRoom"
/>
<!-- Notification Found -->
<item android:id="@+id/action_notify_found1"
android:icon="@drawable/street_view_icon"
android:title="StreetView"
app:showAsAction="ifRoom"
/>
Menu.xml
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
getMenuInflater().inflate(R.menu.menu_dashboard, menu);
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.ic_about));
menu.getItem(1).setIcon(getResources().getDrawable(R.drawable.street_view_icon));
return true;
}
//Notification Icon
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_notify_found:
Intent aboutIntent=new Intent(DashboardActivity.this, HomeAboutActivity.class);
startActivity(aboutIntent);
case R.id.action_notify_found1:
Intent ARStreetviewintent = new Intent(DashboardActivity.this, ARStreetviewActivity.class);
startActivity(new Intent(DashboardActivity.this, StreetviewActivity.class));
default:
return super.onOptionsItemSelected(item);
}
}
。これらのメソッドをオーバーライドして、プロジェクト内のコードを使用します