setDrawerLayout(androidx.drawerlayout.widget.DrawerLayout) is deprecated

use setOpenableLayout(@Nullable Openable openableLayout) Your drawerLayout is implements Openable.


It's ironic that the latest Android Studio (v 4.0.1) itself uses setDrawerLayout(drawer) in its inbuilt NavigationDrawerActivity example.

The fix is very simple. Here's probably what you have:

mAppBarConfiguration = new AppBarConfiguration.Builder(
                R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
                .setDrawerLayout(drawer)           // REPLACE THIS LINE
                .build();

Replace the above mentioned line with the following:

mAppBarConfiguration = new AppBarConfiguration.Builder(
                R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
                .setOpenableLayout(drawer)        // WITH THIS LINE
                .build();

Source: Android Official Reference

The DrawerLayout class implements Openable. So this will simply work without requiring any other change from your end.