I have made one Activity with a NavigationView (opened with a toggle button):
public class MainActivity extends AppCompatActivity implements NavigationView.OnNav
The root cause of this is that you're using the same layout in your Fragment
as you are in the Activity
, and the Toolbar
is inside the container ViewGroup
you transact the Fragment
into. Once a Fragment
has been loaded with its own DrawerLayout
and Toolbar
, it covers the Activity
's Toolbar
, so nothing looks out of the ordinary. However, the toggle in the Fragment
is operating the drawer in the Fragment
, and that drawer is a second NavigationView
that hasn't been setup like the one in the Activity
, so nothing happens when you click on the drawer opened with the toggle. But, if you drag the drawer open, the one that's opening is actually the Activity
's drawer, and that NavigationView
was setup correctly, so clicking on that one works as expected.
The first correction is to move the Toolbar
- its
element, that is - to outside of the RelativeLayout
you're using as the Fragment
container. This will prevent the Activity
's Toolbar
from being obscured when Fragment
s are loaded.
The second step is to define separate, different layout XML files for the Fragment
s. You don't want to use the same layout in the Fragment
s as you are in the Activity
, mostly because that's probably not really what you intend, and also because you really don't want to have multiple, redundant DrawerLayout
s, Toolbar
s, and NavigationView
s, which can cause problems, as you've seen.