這是我onNavigationItemSelected
:在Android的菜單不觸發點擊
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
Intent intent = new Intent(HomeActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
HomeActivity.this.startActivity(intent);
return true;
} else if (id == R.id.nav_extrato) {
//Nothing yet
} else if (id == R.id.nav_bloqueio) {
//Nothing yet
} else if (id == R.id.nav_rede) {
//Nothing yet
} else if (id == R.id.nav_logout) {
signOut();
return true;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
這是我的菜單:http://imgur.com/f2Fpa7C
我在函數的開始一個斷點,只停留在斷點當我點擊在主頁按鈕上。
編輯:我的菜單不是一個列表視圖。這裏是我的菜單:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="@color/background"
app:menu="@menu/activity_home_drawer" />
和 「@菜單/ activity_home_drawer」 是這樣的:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_home"
android:icon="@drawable/home"
android:title="Home" />
<item
android:id="@+id/nav_extrato"
android:icon="@drawable/extrato"
android:title="Extrato" />
<item
android:id="@+id/nav_bloqueio"
android:icon="@drawable/bloqueio"
android:title="Bloqueio" />
<item
android:id="@+id/nav_rede"
android:icon="@drawable/rede"
android:title="Rede Credenciada" />
<item
android:id="@+id/nav_logout"
android:icon="@drawable/exit"
android:title="Logout" />
EDIT 2
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
首頁:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/act_logout"
android:orderInCategory="100"
android:title=""
android:icon="@drawable/blank"
app:showAsAction="always" />
你已經看到你的代碼,你做了什麼?您正在打開當前打開的同一活動,而且沒有動畫。如何注意任何變化 –