Android Question SDK36 and AppCompat Menu In Non-B4X Pages Apps [Solved]

RichardN

Well-Known Member
Licensed User
Longtime User
I have a legacy non-B4X pages app on the store that employs the AppCompat menu. Is this compatible with SDK36?

I have tried various methods of constraining views with panels but the menu side panel always slides in from the top of the physical screen rather than the top of the menu bar. Is there a fix for this?
 

RichardN

Well-Known Member
Licensed User
Longtime User
Thanks @Erel that works with this legacy code. It is more logical and is easier to visualize when you have a panel sized directly to the client area.

The AppCompat menu now works fine with my original manifest but the status bar becomes unreadable except for the battery level. The lower toolbar is acceptable but the status bar need to be returned to black. I have tried several tweaks to the manifest but with no success. What is the correct method of changing this?

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

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#0098FF</item>
        <item name="colorPrimaryDark">#007CF5</item>
        <item name="colorAccent">#AAAA00</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
</resources>
)
 

Attachments

  • Screenshot_20260801_112442.jpg
    Screenshot_20260801_112442.jpg
    69.3 KB · Views: 43
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Thanks @Erel that works just fine. For any other users trying to implement the AppCompat menu into a non-B4X pages in API36 here is some code that will help you on your way.

AppCompat Menu:
Sub Globals

    Private lstMenu As ListView
    Private IME As IME
    Private XUI As XUI
    Private Root As B4XView
  
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    IME.Initialize("ime")
  
    'Define useable client area as a panel -------------------------------------------

    Root = XUI.CreatePanel("")
    Dim Content As Rect = IME.GetContentRect
    Activity.AddView(Root, Content.Left, Content.Top, Content.Width, Content.Height)
    IME.UpdatePercentageReference(Root.Width, Root.Height)

    'Menu Code ------------------------------------------------------------------
  
    Drawer.Initialize(Me, "Drawer", Root, 300dip)        'Init the Drawer to the root panel
    Drawer.CenterPanel.LoadLayout("Main")
  
    ToolbarHelper.Initialize
    ToolbarHelper.ShowUpIndicator = True
  
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(File.DirAssets, "hamburger.png"))
    ToolbarHelper.UpIndicatorDrawable =  bd
  
    ACToolBarLight1.InitMenuListener
    Drawer.LeftPanel.LoadLayout("Left")

    ACToolBarLight1.Title = AppTitle
    Dim MenuOptions() As String = Array As String("First Option","Second Option","Third Option","Last Option")
  
    For i = 0 To MenuOptions.Length -1
        lstMenu.AddSingleLine(MenuOptions(i))
    Next 

End Sub
 
Upvote 0
Top