我无法让我的物品在我的导航抽屉里回复。计划是有一个注销项目,在点击时注销用户。问题是,当我点击项目'退出'它只关闭抽屉,我的代码被忽略。请帮助我,现在已经好几个小时了!
XML code,activitymain
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rebeckagerdtham.skane18.activities.menuActivity"
android:id="@+id/drawerLayout">
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigationmenu"
android:layout_gravity="start"
android:id="@+id/nav_menu">
</android.support.design.widget.NavigationView>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar"
android:id="@+id/mCustomToolbar">
</include>
</android.support.constraint.ConstraintLayout>
XML navigationmenu
<item android:id="@+id/nav_logout"
android:title="Logga ut"
android:checked="false"
/>
<item android:id="@+id/nav_settings"
android:title="Inställningar"
/>
Java代码
public class menuActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
mAuth = FirebaseAuth.getInstance();
//Toolbar modifications
Toolbar my_toolbar = findViewById(R.id.mCustomToolbar);
setSupportActionBar(my_toolbar);
getSupportActionBar().setTitle("Meny");
getSupportActionBar().setLogo(R.drawable.log);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationView nv = (NavigationView) findViewById(R.id.nav_menu);
nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem){
if(menuItem.getItemId()== R.id.nav_logout){
Intent sendToLoginPage = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(sendToLoginPage);
}
return true;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.navigationmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(mToggle.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}