I am adding a panel to an app in code. The panel is not to have rounded corners. The default in the Designer is for a corner radius of 5. How can I change this programatically to 0? Thanks.
Hi .. Are you changing the panels background property ? .. Adding a panel in code results in no rounded corners here unless purposely set.
This results in no rounded corners ...
B4X:
Dim Panel1 As Panel
Panel1.Initialize("")
Panel1.Color = Colors.Blue
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)
This results in corner radius of 10 ... can be set to 0 if this is what your after ..
B4X:
Dim cd As ColorDrawable
cd.Initialize(Colors.Blue,10) 'corner radius = 10 ... set to 0 for no rounded corner
Dim Panel1 As Panel
Panel1.Initialize("")
Panel1.Background = cd
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)
Thanks. I hadn't intended to change the background property, but I can. I was actually hoping for a more direct and straight forward method, but given that the corner radius property is only indirectly available in coding, your schema will work nicely. (It would be great if all the properties were available in both the Designer and through code - hint to Erel). Thanks again.
Dim cd AsColorDrawable
cd.Initialize(Colors.Blue,10) 'corner radius = 10 ... set to 0 for no rounded cornerDim Panel1 AsPanel
Panel1.Initialize("")
Panel1.Background = cd
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)
this is how you add a radius to the panel1.
the code that you have provided is for a non cornered radius
B4X:
Dim Panel1 As Panel
Panel1.Initialize("")
Panel1.Color = Colors.Blue
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)
no in your code u were only creating a rectangle box panel without any radius
by default this is the case when coding the views
when you add the
B4X:
Dim cd AsColorDrawable
cd.Initialize(Colors.Blue,10) 'corner radius = 10 ... set to 0 for no rounded cornerDim Panel1 AsPanel
it will then initialize a radius that will be attached to the panel view.
ok so looking at your first post if you dont want a radius you can either just not initiate a radius to draw or just ad 0 then it wont add a radius to the panel
Correct again .. because that is what mjtaryan wanted .. A panel WithOut any radius
as I stated in #4 .. "if you add a panel by way of code by default it does NOT have rounded corners"
Correct again .. because that is what mjtaryan wanted .. A panel WithOut any radius
as I stated in #4 .. "if you add a panel by way of code by default it does NOT have rounded corners"
I asked the original question because the Designer default is rounded corners with a radius of 5. Until now I've always added the panels I needed in the Designer and reset the radii to 0 there. I've not added a panel in code before and thought all the defaults from the Designer would carry over to code. That is why asked the question.
However, my current project makes an array of panels more efficient which is more easily accomplished in code. Using the code snippet in post #2 (not the rounded corners) I did a little experimenting and discovered that only creating and initializing the panel and then adding it to its intended parent is all that is absolutely necessary to get corners with a radius of 0. Everything else is merely refinement. Therefore, for my purposes, I don't need to reset the panel's color property, which is shown in the snippet. Thanks for the help mj.
I wish (hint to Erel) a) that all the properties could be set directly EITHER in the Designer or in code and b) the property defaults were consistent and the same whether set in the Designer or in code. But at least for now that is not the way it is.