Here is my drawerActivity
public class DrawerActivity extends AppCompatActivity {
public Toolbar toolbar;
public static DrawerLayout drawerLayout;
public ActionBarDrawerToggle drawerToggle;
public NavigationView navigationView;
public Context mContext;
private TextView empname, businame;
private ImageView busiimg;
private String[] drawerItem;
public NavigationView getNavigationView() {
return navigationView;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = DrawerActivity.this;
setContentView(R.layout.activity_drawer);
}
@Override
public void setContentView(int layoutResID) {
drawerLayout = (DrawerLayout)getLayoutInflater().inflate(R.layout.activity_drawer, null);
FrameLayout activityContainer = (FrameLayout) drawerLayout.findViewById(R.id.activity_content);
getLayoutInflater().inflate(layoutResID, activityContainer, true);
super.setContentView(drawerLayout);
initToolbar();
}
public void initToolbar() {
try{
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Manage vendor");
setSupportActionBar(toolbar);
}catch (Exception e){
e.printStackTrace();
}
}
private void setUpNav() {
drawerLayout = findViewById(R.id.activity_container);
drawerToggle = new ActionBarDrawerToggle(DrawerActivity.this, drawerLayout, R.string.app_name, R.string.app_name);
drawerLayout.setDrawerListener(drawerToggle);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
navigationView = findViewById(R.id.nav_main);
drawerToggle.syncState();
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
setUpNav();
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
/* @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_search, menu);
return true;
}*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item))
return true;
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_search) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static void openDrawer(){
drawerLayout.openDrawer(drawerLayout);
}
@Override
public void onBackPressed() {
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
}
Here is the code where I am accessing drawer when image clicked in another activity
drawerImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DrawerActivity.openDrawer();
}
});
I am implementing navigation drawer in my android application. I have a separate activity for navigation drawer. I will extend the drawer activity where ever I want.
Now the issue is I have drawer image in bottom bar. When I click the image in bottom app bar I have to open the drawer. For one activity I want to open drawer by clicking the image in bottom bar. I know if I extend the drawer activity the hamburger icon will visible in toolbar that I don't want to achieve in this activity.
So how to avoid this scenario by using bottom bar?
Extend your draweractivity to your other activity. try this: