#Region Project Attributes
#ApplicationLabel: AppCompatDrawer
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Theme Resources
#AdditionalRes: ..\resource
'MaterialDrawer Resources
#AdditionalRes: ..\md-lib\res
#AdditionalRes: ..\md-app\res
'Activity Type
#Extends: android.support.v7.app.ActionBarActivity
#AdditionalJar: com.android.support:design
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim AC As AppCompat
Dim ABHelper As ACActionBar
Private ActionBar As ACToolBarLight
Private pContent As Panel
Private cbABVisible As ACCheckBox
Dim MDB As MSMaterialDrawerBuilder
Dim MD As MSMaterialDrawer
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
'Set Title and Subtitle for the Toolbar
ActionBar.Title = "AppCompat"
ActionBar.SubTitle = "Toolbar Example 1"
'Because the Toolbar is part of out layout we split up our layout in a main layout file
'(which only has the Toolbar and a ContentPanel) and a content layout which has all the
'visible controls.
pContent.LoadLayout("content")
'sync the controls with current state of ActionBar/Toolbar
cbABVisible.Checked = True
ABHelper.Initialize
'The AppCompat object has some helper methods to get the height for StatusBar, ActionBar and NavigationBar.
'For the ActionBar there are two methods. GetStdActionBarHeight gets the standard ActionBar Height of the device.
'Be aware that this is not necessarily the height defined by the material design guidelines. There is a second
'method GetMaterialActionBarHeight which returns the ActionBar height as defined in the material design guidelines
'regardless of the Android version.
Log("ActionBar Height: " & (AC.GetMaterialActionBarHeight / DipToCurrent(1)))
'Add some MenuItems
'The best method to add action icons to the ActionBar/Toolbar is to load them as drawables.
'With this method it is possible to load icons in different resolutions taking care of the device scale.
'We use the XmlLayoutBuilder library to load the drawables.
Dim xml As XmlLayoutBuilder
Dim bd As BitmapDrawable
bd = xml.GetDrawable("ic_plus_one_black_24dp")
Activity.AddMenuItem3("Plus one", "Menu", bd.Bitmap, True)
bd = xml.GetDrawable("ic_refresh_black_24dp")
Activity.AddMenuItem3("Refresh", "Menu", bd.Bitmap, True)
Activity.AddMenuItem("Overflow1", "Menu")
Activity.AddMenuItem("Overflow2", "Menu")
Activity.AddMenuItem("Overflow3", "Menu")
BuildDrawer
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'Show/Hide the Toolbar. This is done with the new SetLayoutAnimated and SetVisibleAnimated methods of B4A 4.0
Sub cbABVisible_CheckedChange(Checked As Boolean)
If Checked Then
ActionBar.SetLayoutAnimated(200, 0, 0, 100%x, AC.GetMaterialActionBarHeight)
ActionBar.SetVisibleAnimated(200, True)
pContent.SetLayoutAnimated(200, 0, AC.GetMaterialActionBarHeight, 100%x, 100%y - AC.GetMaterialActionBarHeight)
Else
ActionBar.SetLayoutAnimated(200, 0, 0, 100%x, 1dip)
ActionBar.SetVisibleAnimated(200, False)
pContent.SetLayoutAnimated(200, 0, 0, 100%x, 100%y)
End If
End Sub
'Handle Menu Click events. These are the normal B4A Menu item click events.
Sub Menu_Click
Log("MenuItem " & Sender & " selected")
End Sub
Sub BuildDrawer
Dim pnlHdr As Panel
pnlHdr.Initialize("")
pnlHdr.Color = Colors.DarkGray
pnlHdr.Tag = "Header"
MDB.Initialize("MD")
MDB.withHeader(pnlHdr, -1, 80dip)
MDB.AddPrimaryDrawerItem ("Weather" , Null ,Null ,"99+" ,True,1, "Shows the weather")
MDB.AddPrimaryDrawerItem ("Insanity" , Null ,Null ,"2" ,True,2, "")
MDB.AddPrimaryDrawerItem ("Awesome" , Null ,Null ,"" ,True,2, "")
MDB.AddSectionDrawerItem ("Section" ,True)
MDB.AddSecondaryDrawerItem("Settings" ,Null ,Null ,"" ,True ,3)
MDB.AddSecondaryDrawerItem("Help" ,Null ,Null ,"" ,True ,4)
MDB.AddSecondaryDrawerItem("Donate" ,Null,Null ,"" ,False,5)
MDB.AddSecondaryDrawerItem("Yo" ,Null ,Null ,"" ,False,6)
MD = MDB.Build
End Sub