Java Question Navigation Drawer and native ActionBar

corwin42

Expert
Licensed User
Longtime User
I'm trying to create some libraries which will help making the UI of your Apps compliant to the Android Design Guide.

Currently I take a look at the new NavigationDrawer introduced on Google I/O 2013. This library is very simple. You just have to initialize one instance of the NavigationDrawer object and then the Layout of the Activity is replaced with a special "Navigation Drawer" layout.
Now you can access a panel for the navigation sidebar with NavDrawer.NavigationPanel. Normally you should add a listview type view to this panel but you are totally free how you implement the contents. You can load a layout and add any objects you want to the navigation panel. In the example the mListView library from icefairy333 is used because I wanted to have the selected item sticky.

With NavDrawer.ContentPanel you get access to the content of your activity. Instead of adding views to the activity directly you should add all views to this panel.

There is a special SlideDrawable object in the NavigationDrawer library. This is a special drawable (I copied from v4 support library) used for the ActionBar icon animation.

Ok, the NavigationDrawer library was the easy part.

To get things right the navigation drawer has to interact with the ActionBar. I have written a small wrapper class for the ActionBar Class so that "home as up" and such things can be set. The big problem now is that I want to get an event if the home action item is pressed in the action bar. This is currently not possible in B4A I think.
That is because the menu system in B4A is very limited. Perhaps we can use this thread to discuss how to improve the menu system so that it is flexible and compatible to the current implementation.

Erel, have you ever thought about how to improve the menus? I think changing menu items is a must have feature in a future B4A version.

To compile the example you need the newest android.support.v4 library.
 
Last edited:

CidTek

Active Member
Licensed User
Longtime User
You may want to mention that your sample app needs a library called mListview.

EDIT: Oops sorry _ I see that you do mention it.

I'm off to look for it now but this looks very promising.
 

corwin42

Expert
Licensed User
Longtime User
How do I display a non transparent Navigation Drawer?

Just set a color or background drawable to the NavDrawer.NavigationPanel
 

thedesolatesoul

Expert
Licensed User
Longtime User
Yes, I have a lot of trouble mimicing the action bar using AHActionBar (it is a great component, but it is a lot of work if you want advanced configuration).
I think the menu system needs to be more flexible after 4+ (it was perfect for 2.3 devices).
Especially with so many UI patterns emerging now (the new GMail pull to refresh etc). There are many libraries that integrate with ActionBarSherlock (which is becoming pretty standard now).
 

Informatix

Expert
Licensed User
Longtime User
Yes, I have a lot of trouble mimicing the action bar using AHActionBar (it is a great component, but it is a lot of work if you want advanced configuration).
I think the menu system needs to be more flexible after 4+ (it was perfect for 2.3 devices).
Especially with so many UI patterns emerging now (the new GMail pull to refresh etc). There are many libraries that integrate with ActionBarSherlock (which is becoming pretty standard now).

It exists also a class for the action bar which is more flexible and have more features than AHActionBar.
I don't feel very comfortable with the standard Google views and UI elements. Their look can change in a month or in a year, their behavior too. So designing something that can look very differently, or behave differently, under the next OS is not something I'm fond of. And I like to replicate the same interface from Gingerbread to Jellybean, which would be impossible without my own code. I don't feel alone when I see libs like ActionBarSherlock or NineOldAndroids.
Anyway, I offer all my encouragements for this new library.
 

corwin42

Expert
Licensed User
Longtime User
Yes, the actionbar library uses the native ActionBar Class which is available only since Honeycomb. The manifest of the project is not correct with the targetsdkversion.
 

thedesolatesoul

Expert
Licensed User
Longtime User
I don't feel very comfortable with the standard Google views and UI elements. Their look can change in a month or in a year, their behavior too. So designing something that can look very differently, or behave differently, under the next OS is not something I'm fond of. And I like to replicate the same interface from Gingerbread to Jellybean, which would be impossible without my own code.
This is true and I agree. But ofcourse it means more work for the developer.
Recently google has slowed down since ICS in making any big changes to the UI,but there are still some.
 

corwin42

Expert
Licensed User
Longtime User
Since it is currently not possible to use the navigation drawer with the standard android actionbar I changed the library of the navigationdrawer a little bit.

Now in the Initialize method you pass a panel which is a parent for the Content/Navigation Panels. So you can make the navigation drawer any size you like.

New test library and example attached. The example uses a "fake" ActionBar which is not very nice but I think it shows what is possible.

I think the library is Ok now for a first release.
 
Last edited:
Top