B4A Library AHNavigationDrawer - Native Google Navigation Drawer

This is a wrapper library for the native NavigationDrawer introduced by Google at Google I/O 2013.

It contains two objects:

AHNavigationDrawer - This implements the Navigation Drawer
SlideDrawable - This is a special type of drawable used to create an indicator for the NavigationDrawer
MaterialMenuDrawable - This is a drawable which can be used to create the Material Design burger->arrow->cross->check animation.

This Library uses the android-support-v4.jar library which is part of the Android SDK. You have to install it with the Android SDK Manager. In the SDK Manager please add/download the "Extras/Android Support" package. Then you will need to copy the android-support-v4.jar file from <SDK root folder>\extras\android\support\v4 to your B4A custom libs folder!
You need at least the API17 version of the library!

The MaterialMenuDrawable uses the NineOldAndroid animation library. Download the nineoldandroids-2.4.0.jar from here and place it in your custom libs folder (you don't need an xml file for it)

The example uses the mListView library by icefairy333 and the reflection library by agraham.

Changelog:
V1.0:
- Initial version

V1.1:
WARNING: Signature of the event subs have changed!
- Added support for secondary drawer
- Ability to change drawer edge touch sensitivity size

V1.20:
- Fixed the "glitch" while opening the drawer (Sometimes the drawer got "stuck" while swiping open)

V1.21:
- Fixed bug when using NavDrawer.ContentPanel.LoadLayout()

V1.30:
- Some internal changes which should make it compatible with ULV (Ultimate ListView)
- New MaterialMenuDrawable object for Material Design Burger/Arrow/Cross/Check animation
Attention: The MaterialMenuDrawable needs the NineOldAndroids library. See above.

V1.40:
- changed typo for nineoldandroids jar file (Name change: nineoldandroid-2.4.0.jar to nineoldandroids-2.4.0.jar). If you update from older version just change nineoldandroid-2.4.0.jar in your CustomLibs folder to nineoldandroids-2.4.0.jar

Screenshot_2013-08-01-09-49-05.png
 

Attachments

  • AHNavigationDrawerExample1_1.zip
    323.7 KB · Views: 2,638
  • DoubleNavigationDrawerExample1_0.zip
    324 KB · Views: 1,837
  • AHNavigationDrawer1_40.zip
    27.8 KB · Views: 1,535
Last edited:

Inman

Well-Known Member
Licensed User
The new version fixed the issue and works great. New arrow animation works well too. Couple of issues though.

1. The nineolds library file that is downloaded is nineoldandroids-2.4.0.jar but your library is expecting nineoldandroid-2.4.0.jar (without s before -). No issues, just need to rename the jar file or correct the XML file.

2. When a drawer slide is in progress, navdrawer_DrawerSlide (Position As Float, DrawerGravity As Int) has the values that are required to animate the arrow properly. But the DrawerGravity returned has a value of 8388611 for the drawer on the left while NavDrawer.GRAVITY_LEFT has a value of 3 which is same as Gravity.Left. Again, no big deal. Just need to make sure what value you are checking against, to identify the correct drawer (when there are multiple drawers).
 

imgsimonebiliato

Well-Known Member
Licensed User
Hello,
during compile I've got this error "A referenced library is missing: nineoldandroid-2.4.0".
I read what you wrote about this library and I've done everything.

What's the matter?
 

RandomCoder

Well-Known Member
Licensed User
See the previous post. The name nineoldandroids-2.4.0.jar needs the s removing from the name.
 

imgsimonebiliato

Well-Known Member
Licensed User
Thanks.
Please, I can't understand what this function do:


B4X:
Sub GetNPDrawable(Name As String) As Object
Dim r As Reflector
Dim package As String
Dim id As Int
package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
id = r.GetStaticField(package & ".R$drawable", Name)
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
Return r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub
 

corwin42

Expert
Licensed User

corwin42

Expert
Licensed User

imgsimonebiliato

Well-Known Member
Licensed User
Hello,
could you please help me with this log error?


B4X:
** Activity (main) Create, isFirst = true **


java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/widget/DrawerLayout$LayoutParams;
    at de.amberhome.navdrawer.NavigationDrawer.Initialize2(NavigationDrawer.java:82)
    at de.amberhome.navdrawer.NavigationDrawer.Initialize(NavigationDrawer.java:67)
    at de.amberhome.NavDrawer.main._activity_create(main.java:292)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at de.amberhome.NavDrawer.main.afterFirstLayout(main.java:98)
    at de.amberhome.NavDrawer.main.access$100(main.java:16)
    at de.amberhome.NavDrawer.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5834)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.widget.DrawerLayout$LayoutParams" on path: DexPathList[[zip file "/data/app/de.amberhome.NavDrawer-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 17 more
    Suppressed: java.lang.ClassNotFoundException: android.support.v4.widget.DrawerLayout$LayoutParams
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 18 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
 
Last edited:

RandomCoder

Well-Known Member
Licensed User
Have you followed this advice from post 1...

This Library uses the android-support-v4.jar library which is part of the Android SDK. You have to install it with the Android SDK Manager. In the SDK Manager please add/download the "Extras/Android Support" package. Then you will need to copy the android-support-v4.jar file from <SDK root folder>\extras\android\support\v4 to your B4A custom libs folder!
 

Dave61

Member
Licensed User
Probably doing something stupid but here goes!

I implemented this Navigation Drawer in a project and it works fine. But feedback from users is that they want it to look more modern - i.e. material design.
This project uses Samsung tablets that we supply so they are all Lollipop minimum.
So, I tried changing the Manifest Editor my modifying these 2 lines:

<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="21"/>
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

as mentioned in the 'Material Design 1 - Basics' tutorial (which I have working fine). I also added the resources of course & made them read-only.
However, in the resulting app, the drawer sits underneath the action bar instead of being integrated in it...screen dump attached.

Is there more I need to do to get this looking right? I was reading through the 2nd Material Design tutorial but, as I am only developing for Android 5, I am guessing (possibly incorrectly) that I don't need to worry about AppCompat and all the other steps involved in that tutorial to get controls looking correct for material design.
 

Attachments

  • tempFileForShare_2015-07-31-16-11-22.jpg
    tempFileForShare_2015-07-31-16-11-22.jpg
    89.1 KB · Views: 104

imgsimonebiliato

Well-Known Member
Licensed User
Hello,
does it works on Android 5.1?
Because I click on the ActionBar button, but the drawer don't appear
 

corwin42

Expert
Licensed User
Hello,
does it works on Android 5.1?
Because I click on the ActionBar button, but the drawer don't appear
yes but there was a problem with old B4A versions. Be sure to use B4A 4.00 or above and use the Activity_ActionBarHomeClick event.
 
D

Deleted member 30048

Guest
hello, I get error if I use this library in conjunction with AdMob. The error that shows is the one shown in the picture.

I once had the same problem but I used a unknow version of android-support-v4 and worked well, but I no longer have that version.

How I can use this library and admob together?

Thanks!
 

Attachments

  • error.png
    error.png
    166.5 KB · Views: 78

corwin42

Expert
Licensed User
hello, I get error if I use this library in conjunction with AdMob. The error that shows is the one shown in the picture.

I once had the same problem but I used a unknow version of android-support-v4 and worked well, but I no longer have that version.

How I can use this library and admob together?

This is not related to this library.

See here.
 
Top