问题
I'm working on a Android project that only support API level > 14. As a consequence, we don't use the Android Support Library.
I would like to use the navigation drawer with the newer API, but all the documentation I found is about how to create navigation drawer using the support library.
How can I create a Activity with a navigation drawer using only the Android SDK with API level > 14?
回答1:
You simply use the support library as it contains the functionality you need. It does not matter that you do not want to use the other functionality contained within the library. It does contain the sliding menu that you want to use so just use it.
The alternative is to write your own code or use a different library.
Try not to think of the support library as "only for backwards compatibility". It provides functionality that is not included in the standard SDK's (such as ViewPager
and SlidingDrawer
)
回答2:
From the looks of it, the ONLY DrawerLayout implementation comes from the SupportLib (ie. there is not another source of this code).
Also, from the looks of it, it was introduced in API 19, so your API 14 min wouldn't be adequate anyway.
Bottom line, you should just include the SupportLibrary, and move on with your life, there is no significant issue including this library, and it will be much more work to try and create a workaround.
回答3:
You can either extract it from the support library v4 source code or use 3rd party library like SlidingMenu
There once was an alternative/official implementation called SlidingDrawer, however it is deprecated since API Level 17.
This is not hard to understand, there are many fancy features which is not contained in the official SDK release. Just go for what you want and don't pay too much attention to where it is from.
来源:https://stackoverflow.com/questions/22301924/how-to-create-a-navigation-drawer-without-support-library