Sideslip menu effect realized by drawerlayout in Android

As we all know, we are very familiar with a function in Android, the sideslip menu effect. In the past, most of us used the slidingmenu, an open-source framework. Since Google's official new drawerlayout control, more and more applications began to use Google's official control to write this effect. Without much to say, let's send a picture first to show my sincerity:

Start writing code

Drawerlayout is included in V4 package, so V4 package needs to be added to the project. I won't say much about how to add it. Navigationview needs to add compile 'com. Android. Support: Design: 25.1.0' in build.gradle

activity_ main.xml

Then add a menu folder in the res folder, and you don't need to add what has been added

In the above code, there is an app: menu = "@ menu / activity" in navigationview_ main_ "Drawer" corresponds to the following: add a menu file with any name. My name is activity_ main_ drawer.xml

activity_ main_ drawer.xml

Add another layout

In the above code, app: headerlayout = "@ layout / NAV_ header_ "Main" corresponds to the following: add a layout named NAV_ header_ main.xml

nav_ header_ main.xml

MainActivity:

drawer.openDrawer(GravityCompat.START);// Open slide menu

drawer.closeDrawer(GravityCompat.START);// Close slide menu

drawer.isDrawerOpen(GravityCompat.START);// Judge whether the sliding menu is open

Specific source demo download address

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>