enter image description hereI followed a tutorial on how to add a side navigation drawer but after adding it properly i can`t interact no more with the textedits/maps etc in my fragments, it´s not registering touch for that layout only for the drawer buttons itself.
enter image description here
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:itemBackground="#drawable/drawable_selector"
app:itemIconTint="#drawable/color_selector"
app:itemTextColor="#drawable/color_selector"
app:menu="#menu/bottom_nav_menu"/>
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<androidx.drawerlayout.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/purple_200"
android:id="#+id/toolbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp"/>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:theme="#style/NavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="#+id/nav_view"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_menu"
android:background = "#color/purple_700"
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
/>
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Main activity:
public class MainActivity extends AppCompatActivity {
ActivityMainBinding binding;
private DrawerLayout drawer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
replaceFragment(new HomeFragment());
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
binding.bottomNavigationView.setOnItemSelectedListener(item -> {
switch (item.getItemId()){
case R.id.home:
replaceFragment(new HomeFragment());
break;
case R.id.dashboard:
replaceFragment(new DashboardFragment());
break;
case R.id.pregnant:
replaceFragment(new Pregnant());
break;
}
return true;
});
}
public void onBackPressed(){
if(drawer.isDrawerOpen(GravityCompat.START)){
drawer.closeDrawer(GravityCompat.START);
}else {
super.onBackPressed();
}
}
private void replaceFragment(Fragment fragment){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frameLayout, fragment);
fragmentTransaction.commit();
}
}
I also have and xml for the nav header and the drawer itself with some textview, items etcenter image description here
If i bringToFront() the layout it works but the drawer dissapears
Related
I have a navigation bar with fragment container inside. I have added an imageview in it.My problem is to replace fragment container with a new fragment when I choose an item in the navigation bar. When i choose an item on the navigation bar, it opens but fragment container still appear behind.
I would like to open an item on the navigation bar and the fragment container is fully overwritten by the new fragmement.
Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="50dp"
android:layout_height="?attr/actionBarSize"
android:background="#00000000"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:fitsSystemWindows="true"
/>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/imageView"
android:layout_marginLeft="80dp"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginBottom="17dp"
app:layout_constraintBottom_toTopOf="#+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/logo" />
</FrameLayout>
</FrameLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/nav_header_menu"
app:defaultNavHost="true"/>
</androidx.drawerlayout.widget.DrawerLayout>
public class MainActivity extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager2 viewPager2;
private MyFragment adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = findViewById(R.id.tabLayout);
viewPager2 = findViewById(R.id.viewPager2);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer=(DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView=(NavigationView)findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(item -> {
item.setChecked(true);
switch (item.getItemId())
{
case R.id.nav_materials:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,new suppliers()).commit();
break;
case R.id.nav_interiorDesign:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,new interiorDesign()).commit();
break;
case R.id.nav_Architects:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,new architect()).commit();
break;
case R.id.nav_contractors:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,new contractorList()).commit();
break;
case R.id.nav_Permit:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,new buildPermit()).commit();
break;
case R.id.nav_kanban:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new kanbanManagement()).commit();
break;
case R.id.nav_Estimator:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container,new costEstimator()).commit();
break;
case R.id.navigation_dashboard:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new dashboard()).commit();
break;
case R.id.nav_funds:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new finance()).commit();
break;
case R.id.nav_sign_out:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new signOut()).commit();
break;
//add other fragments#
}
drawer.closeDrawer(GravityCompat.START);
return true;
});
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawer, toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//changing the color of hamburger icon
toggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.black));
drawer.addDrawerListener(toggle);
toggle.syncState();
}
I'm almost new to programming in Android and there are still things that I don't handle very well. Now I'm doing a project in Android using java that has me half frustrated since I've been trying to find and fix a problem for WEEKS but I still can't identify what it is. The app consists of a view that contains a drawer layout with a series of "options", it also contains a viewpager2 and a bottom navigation with 2 other "options." The error appears when I press the bottom navigation tabs since the two fragments they overlap each other, the same happens when I select an option from the navigation drawer, the fragments are superimposed, then I leave you part of my code so that I hope you can help me, thank you very much for taking the time to help me.
main:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
DrawerLayout drawerLayout;
ActionBarDrawerToggle actionBarDrawerToggle;
Toolbar toolbar;
NavigationView navigationView;
//variables para cargar el fragment
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
String personName;
ViewPager2 viewPager2;
BottomNavigationView bottomNavigationView;
ViewPagerAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=findViewById(R.id.toolbar);
setSupportActionBar(toolbar);//se pasa el toolbar
drawerLayout=findViewById(R.id.drawer);
navigationView=findViewById(R.id.navigationView);
navigationView.setNavigationItemSelectedListener(this);
actionBarDrawerToggle=new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.open,R.string.close);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
actionBarDrawerToggle.syncState();
initView();
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
if (item.getItemId() == R.id.user){
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
fragmentManager=getSupportFragmentManager();
fragmentTransaction=fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new perfil_user());
fragmentTransaction.commit();
}
else if (item.getItemId() == R.id.exit){
finish();
}
//aquí van las otros fragment
drawerLayout.closeDrawer(GravityCompat.START);
return false;
}
private void initView() {
viewPager2 = findViewById(R.id.vp_horizontal_ntb);
viewPager2.setOffscreenPageLimit(100);
bottomNavigationView = findViewById(R.id.navigation);
adapter = new ViewPagerAdapter(this);
viewPager2.setAdapter(adapter);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
Fragment fragment=null;
switch (item.getItemId()){
case R.id.perfil:
fragment=new perfil_user();
break;
case R.id.generar_debate:
fragment=new genera_debate();
break;
}
if (fragment != null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
return true;
}
});
}
}
files xml:
content main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
drawer toolbar:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#067B30"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
app:menu="#menu/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
android:foreground="?attr/selectableItemBackground" />
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/vp_horizontal_ntb"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
activity main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/drawer_toolbar"
>
</include>
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/content_main"
>
</include>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="#menu/drawer_menu"
app:headerLayout="#layout/drawer_header"
android:layout_gravity="start"
android:fitsSystemWindows="true"
>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
Toolbar menu is inflated in fragment but then cleared later.
When activity is first created (or rotated) the toolbar menu is inflated properly in the fragment, but then gets cleared before it can be displayed.
I set the toolbar menu in my fragment's onActivityCreated, and it stays set through onResume in the activity. The next call I've found is in onCreateOptionsMenu in the activity, but at this point toolbar.getMenu().size() = 0
Somewhere between onResume and onCreateOptionsMenu the toolbar menu is getting reset.
Edit:
I'm not sure what is necessary to reproduce it, but here is all(?) of the relevant code.
Activity:
private Toolbar toolbar;
private DrawerLayout drawer;
private ActionBarDrawerToggle toggle;
private FloatingActionButton fab;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fab = findViewById(R.id.main_fab);
drawer = findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(this, drawer,toolbar,R.string.nav_drawer_open,R.string.nav_drawer_close);
drawer.addDrawerListener(toggle);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (savedInstanceState == null) {
showFragment(ScheduleFragment.newInstance());
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(toggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
CharSequence retainTitle = toolbar.getTitle();
super.onPostCreate(savedInstanceState);
toggle.syncState();
toolbar.setTitle(retainTitle);
}
Fragment:
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
toolbar = ((MainActivity)getActivity()).getToolbar();
setMenuAction(MENU_ACTION_DELETE);
}
protected void setMenuAction(int menuAction) {
Log.d(logger, "setting the menu");
switch(menuAction) {
case MENU_ACTION_DELETE:
toolbar.getMenu().clear();
toolbar.inflateMenu(R.menu.menu_delete);
break;
case MENU_ACTION_NONE:
Log.d(logger, "clearing menu");
toolbar.getMenu().clear();
break;
}
}
Layouts:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout">
<include
layout="#layout/activity_main"/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/menu_nav" />
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|snap|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/main_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#drawable/ic_baseline_add_24px"
android:layout_margin="16dp" />
<include layout="#layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<FrameLayout
android:id="#+id/fragmentHolder"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
The problem in my current code as posted was the line setSupportActionBar(toolbar);
This was not needed, and was in fact causing the troubling lifecycle problems stated above.
i have bottom navigation and navigation drawer and i set home screen fragment as default
now problem is when i run my app on Emulator hamburger icon and bottom navigation is showing and home Fragment by default
when i click to hamburger icon its not working
when i remove default home fragment then navigation drawer is working
How to solve this Problem so both navigationDrawer and bottom navigation will work
HomeScreenActivity.java
public class HomeScreenActivity extends AppCompatActivity {
DrawerLayout mDrawerLayout;
ActionBarDrawerToggle mToggle;
BottomNavigationView bottomNavigationView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
bottomNavigationView = findViewById(R.id.homeScreenBottomNavigation);
bottomNavigationView.setOnNavigationItemSelectedListener(bottomNavListener);
// getSupportFragmentManager().beginTransaction().replace(R.id.homeScreenframeLayout, new HomeFragment()).commit();
mDrawerLayout = findViewById(R.id.HomeScreenDrawerLayout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
private BottomNavigationView.OnNavigationItemSelectedListener bottomNavListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
Fragment selectedFragment = null;
switch (menuItem.getItemId()) {
case R.id.bottomNavHome:
selectedFragment = new HomeFragment();
break;
case R.id.bottomNavAdd:
selectedFragment = new AddFragment();
break;
case R.id.bottomNavSearch:
selectedFragment = new SearchFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.homeScreenframeLayout, selectedFragment).commit();
return true;
}
};
}
ActivityHomeScreen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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=".HomeScreenActivity"
>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/HomeScreenDrawerLayout"
>
<android.support.design.widget.NavigationView
app:headerLayout="#layout/left_navigation_header"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/navigationView"
app:menu="#menu/drawer_layout"
android:layout_gravity="start"
android:background="#ffff"
>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/homeScreenframeLayout"
>
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/homeScreenBottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_navigation"
android:background="?android:attr/windowBackground"
>
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
The issue is with your ActivityHomeScreen.xml. You have to make DrawerLayout as the parent view. Inside that you have to place BottomNavigationDrawer and remaining code.
And You havent created custom appbar for naviagtion drawer(it now comes with navigation drawer template)
Your ActivityHomeScreen.xml should look like this:
ActivityHomeScree.xml
<?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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Now create a layout file app_bar_main.xml. Inside it create a toolbar and place your frameLayout here.
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<!--
Place your frameLayout here
-->
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
app:menu="#menu/navigation" />
</android.support.design.widget.CoordinatorLayout>
Now both Navdrawer and BottomNavigationDrawer should work.
I have a Navigation Drawer Activity, however, I'm using a Fragment inside of the drawer. I can't get both data binding and the fragment working together. With the example code the data binding doesn't work. If I change binding = ContentNewSessionBinding.inflate(getLayoutInflater()) to binding = DataBindingUtil.setContentView(this, R.layout.content_new_session_); I get an error that a view cannot be found the fragment.
activity_new_session.xml
<?xml version="1.0" encoding="utf-8"?>
<layout
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.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_new_session_"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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">
<FrameLayout
android:id="#+id/new_session_draw_frame"
android:name="uk.co.alexanderjs.catchtrack2.SpeciesManager_Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</layout>
content_new_session.xml
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="WeatherModel"
type="uk.co.alexanderjs.models.WeatherModel"/>
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/CL_content_new_session"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".NewSession_Activity"
tools:showIn="#layout/app_bar_new_session_">
<android.support.constraint.ConstraintLayout
android:id="#+id/CL_info_tray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/IV_location_type_info_tray"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/IV_watch_info_tray"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_cell_tower" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
NewSession_Activity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_session)
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
toggle.setDrawerIndicatorEnabled(false);
Class fragmentClass = SpeciesManager_Fragment.class;
Fragment fragment = null;
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e ) {
e.printStackTrace();
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.new_session_draw_frame, fragment);
fragmentTransaction.commit();
}
ContentNewSessionBinding binding = ContentNewSessionBinding.inflate(getLayoutInflater());
binding.setWeatherModel(MainActivity.weatherModel);
}
You should try to move that FrameLayout in your activity_new_session.xml outside the NavigationView, between the toolbar layout and the NavigationView is the place for the fragment container and then you can add to your NavigationView:
app:headerLayout="YourHeaderLayout"
in case you want to have a header in your DrawerLayout
app:menu="YourMenuXml"
where you have the items that will show on your DrawerLayout