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 ScrollView
Private cbABVisible As ACCheckBox
Private cbABShadow As ACCheckBox
Private cbShowAsUp As ACCheckBox
Private edTitle As ACEditText
Private edSubTitle As ACEditText
Private cbShowLogo As ACCheckBox
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 the Toolbar (from the loaded layout) as the ActionBar of this activity.
ActionBar.SetAsActionBar
'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("cardlayout")
' pContent.Panel.LoadLayout("cardlayout")
pContent.Panel.LoadLayout("content")
'sync the controls with current state of ActionBar/Toolbar
cbABVisible.Checked = True
edTitle.Text = ActionBar.Title
edTitle.Hint = "Title"
edSubTitle.Text = ActionBar.SubTitle
edSubTitle.Hint = "SubTitle"
ABHelper.Initialize
ABHelper.ShowUpIndicator = True
'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")
'
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
'Show/Hide Toolbar Shadow. This only works on Android 5.0 and above.
Sub cbABShadow_CheckedChange(Checked As Boolean)
If Checked Then
AC.SetElevation(ActionBar, 8dip)
Else
AC.SetElevation(ActionBar, 0dip)
End If
End Sub
'Show Toolbar with "up" navigation icon.
Sub cbShowAsUp_CheckedChange(Checked As Boolean)
If Checked Then
ABHelper.ShowUpIndicator = True
Else
ABHelper.ShowUpIndicator = False
End If
End Sub
'Sync edittext field with Toolbar Title
Sub edTitle_TextChanged (Old As String, New As String)
If Old <> New Then
ActionBar.Title = edTitle.Text
End If
End Sub
'Sync edittext field with Toolbar Subtitle
Sub edSubTitle_TextChanged (Old As String, New As String)
If Old <> New Then
ActionBar.SubTitle = edSubTitle.Text
End If
End Sub
'Show/Hide a Logo
Sub cbShowLogo_CheckedChange(Checked As Boolean)
If Checked Then
ActionBar.LogoBitmap = LoadBitmap(File.DirAssets, "b4a_180.png")
Else
ActionBar.LogoBitmap = Null
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 Activity_ActionBarHomeClick
Log("activity home")
End Sub