First question here, hope I'll get the help I need :) First of all I tried to check at this thread: Same Navigation Drawer in different Activities and a lot others and got nothing :\
Question:
So I make a app that supposed to be built like this:
Navigation Drawer - over all the activities.
Main page that contain information
Activity
I made the options on the drawer to go to another activities but:
- How do I make the drawer be visible on the other activities?
How do I make an option that when I'm currently in an activity and I press in the drawer again on the button that send me to the same activity it will just close the drawer? there is any option to check if I'm right now in a specific activity? here is my main page with the drawer:
public class Main_Page extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main__page); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); } @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { Intent Home=new Intent(Main_Page.this,Main_Page.class); Intent Settings = new Intent(Main_Page.this,Settings.class); int id = item.getItemId(); if (id == R.id.Main_App) startActivity(Home); else if (id== R.id.nav_Settings) startActivity(Settings); else if (id == R.id.Nav_Log_Out) { super.onBackPressed(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } }
Thank you !