Method setDrawerListener is deprecated

While I'm doing something on my app, I see that the navigation drawer on my app reduced its size. But I'm not doing anything on that.

navigation drawer

Then, after checking the code, I saw that setDrawerListener is deprecated. Does anyone has a solution to this?

drawerLayout.setDrawerListener(actionBarDrawerToggle);

Solution 1:

Use addDrawerListener() instead.

Solution 2:

Replace:

drawer.setDrawerListener(...);

with

drawer.addDrawerListener(...);

public void setDrawerListener(DrawerLayout.DrawerListener listener) Sets a listener to be notified of drawer events.

Note that this method is deprecated and you should use addDrawerListener(DrawerLayout.DrawerListener) to add a listener and removeDrawerListener(DrawerLayout.DrawerListener) to remove a registered listener.