Android Question How to i) change the Menu Bar BACKGROUND color to be SAME as the ACTION BAR BACKGROUND COLOR or ii) change the Text Color of ONLY THE MENU ITEM

beelze69

Active Member
Licensed User
Longtime User
Hi,

Presently, in my B4XPages app I have the Action Bar with a 'Blue' background with 'White' foreground text and it is extremely well readable.

Ps. note: I referred Erel's Post in this regard.

However, when I add a Menu-item to it, the background colour of the Menu Item is 'White' and the Foreground is also 'White' and so it is not readable.

My manifest entries are:
B4X:
CreateResource(values, colors.xml,
<resources>
    <color name="actionbar">#0000FF</color> 'blue
    <color name="statusbar">#0000FF</color> 'blue
    <color name="textColorPrimary">#FFFFFFFF</color> 'white
    <color name="navigationBar">#0000FF</color> 'blue
    <color name="window">#FF5B7BFF</color>
</resources>
)

Suppose I change the textColorPrimary to 'Black' say, then the text in the Menu Item becomes visible (since it is 'Black' over 'White') but the Text in the Status Bar is not readable at all ('Black' over 'Blue')...

So is it possible to:

i) change the Background color of the Menu Item to the same as the Action/ Status Bar colour i.e. 'Blue' so that the Menu item is visible and the 'textColorPrimary can be kept as 'White' only(in my case)..

ii)change the foreground color of only the Menu Item Text to some other color eg. Red(so that Red looks readable over White) Without changing the Foreground Text color of the Action/Status Bar (which remains White in my case)?

iii) thirdly, in the Themes example given by Erel, an Icon is added to the status bar with the Code ...

B4X:
Activity.AddMenuItem3("", "refresh", LoadBitmapResize(File.DirAssets, "ic_cached_white_24dp.png", 32dip, 32dip, True), True)



However, the B4XPages does not provide this Method to add an Icon...
It has : B4XPages.AddMenuItem( Me, "Home")

So how can we add an Icon to the Status Bar in a B4X Pages App and then invoke its click event via code ?

Ps. I do not want to change the 'Blue' colour of the Status Bar since it gels well with my App.

Requesting for guidance on the same,

Thanks.
 
Last edited:

William Lancee

Well-Known Member
Licensed User
Longtime User
Look at @Erel 's informative example

https://www.b4x.com/android/forum/threads/b4x-b4xpages-menu-badges.133301/

Instead of a bitmap of cart and badge use the sub below to draw a bitmap of anything you like.
B4X:
'Call with     Dim bmp As B4XBitmap = CreateIcon("ABC", 16, xui.Color_White, xui.Color_Blue)
Private Sub CreateIcon (text As String, TextSize As Int, TextColor As Int, BackgroundColor As Int) As B4XBitmap
    IconCanvas.DrawRect(IconCanvas.TargetRect, BackgroundColor, True, 0)
    Dim fnt As B4XFont = xui.CreateDefaultBoldFont(TextSize)
    Dim metrics As B4XRect = IconCanvas.MeasureText(text, fnt)
    IconCanvas.DrawText(text, IconCanvas.TargetRect.Width/2 - metrics.width/2, IconCanvas.TargetRect.Height/2 + metrics.height/2, fnt, TextColor, "LEFT")
    Return IconCanvas.CreateBitmap
End Sub

FYI Your title of the thread doesn't attract answers because: it is two questions and you are (what is the convention here) shouting in caps.
 
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
Look at @Erel 's informative example

https://www.b4x.com/android/forum/threads/b4x-b4xpages-menu-badges.133301/

Instead of a bitmap of cart and badge use the sub below to draw a bitmap of anything you like.
B4X:
'Call with     Dim bmp As B4XBitmap = CreateIcon("ABC", 16, xui.Color_White, xui.Color_Blue)
Private Sub CreateIcon (text As String, TextSize As Int, TextColor As Int, BackgroundColor As Int) As B4XBitmap
    IconCanvas.DrawRect(IconCanvas.TargetRect, BackgroundColor, True, 0)
    Dim fnt As B4XFont = xui.CreateDefaultBoldFont(TextSize)
    Dim metrics As B4XRect = IconCanvas.MeasureText(text, fnt)
    IconCanvas.DrawText(text, IconCanvas.TargetRect.Width/2 - metrics.width/2, IconCanvas.TargetRect.Height/2 + metrics.height/2, fnt, TextColor, "LEFT")
    Return IconCanvas.CreateBitmap
End Sub

FYI Your title of the thread doesn't attract answers because: it is two questions and you are (what is the convention here) shouting in caps.
Hi William,

Thanks ! I will try your solution...

By the way , I typed in caps just to emphasize ..I am sorry. I never intended to shout...I have changed everything above.. Pasting separately the 2 questions (since they are related)...
I am requesting for help in this regard, since all I want is to be able give separate colors for the foreground text of the Menu Bar and Status Bar...

So, is it possible to :

i) change the Background color of the Menu Item to the same as the Action/ Status Bar colour i.e. 'Blue' so that the Menu item is visible and the 'textColorPrimary can be kept as 'White' only(in my case)..

ii)change the foreground color of only the Menu Item Text to some other color eg. Red(so that Red looks readable over White) Without changing the Foreground Text color of the Action/Status Bar (which remains White in my case)?

Thanks
 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
???
1.gif
 
Upvote 0
Top