Android Question Panel BorderColor

Declan

Well-Known Member
Licensed User
Longtime User
Hi have an array of Panels.
I am using the following code to change the Color of the Panel.
B4X:
calPanels(pnlNumber).Color = Colors.Cyan
How do I change the BorderColor of the Panel?
 

Ohanian

Active Member
Licensed User
Longtime User
Hi have an array of Panels.
I am using the following code to change the Color of the Panel.
B4X:
calPanels(pnlNumber).Color = Colors.Cyan
How do I change the BorderColor of the Panel?

Hi,
B4X:
    Dim cdPanel As ColorDrawable   
    cdPanel.Initialize2(Colors.Red, 0, Colors.Black, 1)
    calPanels(pnlNumber).Background = cdPanel
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Hi,
B4X:
    Dim cdPanel As ColorDrawable 
    cdPanel.Initialize2(Colors.Red, 0, Colors.Black, 1)
    calPanels(pnlNumber).Background = cdPanel
Thanks, but that changes the Background color.
I only want to change the border color.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
This should work (for non-rounded borders)
B4X:
Dim cv as Canvas
cv.Initialize(calPanels(pnlNumber))
cv.DrawColor(Colors.Red)    'Background
Dim dstRect as Rect
dstRect.Initialize(0,0,calPanels(pnlNumber).Width, calPanels(pnlNumber).Height))
cv.DrawRect(dstRect, Colors.Green, False, 4dip)     'Border color and width
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
This should work (for non-rounded borders)
B4X:
Dim cv as Canvas
cv.Initialize(calPanels(pnlNumber))
cv.DrawColor(Colors.Red)    'Background
Dim dstRect as Rect
dstRect.Initialize(0,0,calPanels(pnlNumber).Width, calPanels(pnlNumber).Height))
cv.DrawRect(dstRect, Colors.Green, False, 4dip)     'Border color and width
Many thanks - works great
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
Thanks, but that changes the Background color.
I only want to change the border color.
There is nothing wrong with the code. It changes background colour and the border colour. If you want to only change the border colour, have the first parameter to Initialize2 set to the same colour as your panel background (you know what the colour of your background is), and only change the fourth parameter which is the colour of the border. You can set the border width and border corner radius as well.
Why would you want to draw a rectangle on top of the panel, if it is easier to do this way?
 
Upvote 0
Top