Android Question Using a ToolBar as ActionBar at Runtime


Licensed User
Longtime User
Its my first time using Toolbar ( (AppCompat 3.30)

I dont really use Layout (designer) so i always initialize and add most of my object/views via code.

Here is my code, and i cant see my toolbar. Is this a bug?

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim mainToolbar As ACToolBarLight
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.Initialize("Activity") 'toolbar not visible even if i remove this
   Activity.AddView(mainToolbar, 0dip, 0dip, 100%x, 56dip)
   mainToolbar.PopupTheme = mainToolbar.THEME_LIGHT
   mainToolbar.Title = "Title"
   mainToolbar.TitleTextColor = Colors.White
   mainToolbar.SubTitle = "Sub Title"
   mainToolbar.SubTitleTextColor = Colors.White
   mainToolbar.Elevation = 4dip
End Sub

Toolbar will only be visible if I apply colors on it;
    Dim cd As ColorDrawable
    cd.Initialize(0xFFF44336, 0)
    mainToolbar.Background = cd

SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#F44336</item>
        <item name="colorPrimaryDark">#D32F2F</item>
        <item name="colorAccent">#FFC107</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="windowActionModeOverlay">true</item>