I have an activity which has a navigationView
and a toolbar
(I set toolbar name manually).
My problem is; when I open the navigationView, it goes out of activity and back to previous activity.
I tried many ways to find the problem and I found when i wasn't using this line the problem has been solved and navigation menu opens without any problem.
setSupportActionBar(toolbar);
I don't know which one the problem is? toolbar or navigation?
Note : There is nothing special about the styles.
Activity :
Toolbar toolbar = findViewById (R.id.toolbar_StudentList);
setSupportActionBar(toolbar);//Set actionBar with toolbar
if(getSupportActionBar() != null)
{
getSupportActionBar().setDisplayShowTitleEnabled(false);//Remove actionBar title
toolbar.setTitle(mClassEntry.getClassName());
}
DrawerLayout drawer = findViewById (R.id.drawerLayout_StudentList);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this , drawer , toolbar , 0b0, 0);
toggle.syncState();
NavigationView drawerItems = findViewById (R.id.navigationView_StudentList);
drawerItems.setNavigationItemSelectedListener(item -> {
.
.
.
}
Xml :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.user.classmanager.StudentActivity"
android:id="@+id/drawerLayout_StudentList"
style="@style/DrawerLayout_all"
>
<FrameLayout
android:id="@+id/frameLayout_StudentList"
style="@style/Width_height_all_both_matchParent"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_StudentList"
style="@style/ToolBar_all"
/>
<RelativeLayout
style="@style/RelativeLayout_searchView_all"
>
<android.support.v7.widget.SearchView
android:id="@+id/searchView_StudentList"
style="@style/SearchView_all"
/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_StudentList"
style="@style/RecyclerView_FrameLayout_all"
/>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigationView_StudentList"
style="@style/NavigationView_StudentList"
/>
</android.support.v4.widget.DrawerLayout>
Also my toolbar has a icon to close activity :
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.toolbar_backicon, menu);//Back item in Toolbar
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item)
{
finish();//close activity
return super.onOptionsItemSelected(item);
}