Android Question Change TextSize of all buttons - B4XPages

calloatti

Member
Licensed User
I am trying to change the TextSize of all buttons in all the existing pages in B4XMainPage or at least in each page B4XPage_Created, but I have no idea how to get a reference to each b4xpage, or even to the b4xpage in its B4XPage_Created event.

And then I have no idea if that b4xpage reference in the actual container of the buttons I added in the visual designer anyway...

I found this: https://www.b4x.com/android/forum/t...hole-application-in-android.96308/post-607642 but it does not apply to B4XPages.

I tried these in a B4XPage_Created event, they don't work:

B4X:
    For Each b As Button In B4XPages.GetNativeParent(Me)
       
        If b Is Button Then Log("button") 'b.TextSize = 12
       
    Next


    For Each b As Button In Root
       
        If b Is Button Then Log("button") 'b.TextSize = 12
       
    Next
 

calloatti

Member
Licensed User
Thank you so much. Could you be so kind to provide an example for doing it in each b4xpage_created event? And sorry for such basic questions, this is only my second app using B4A.

Edit: Its probably Root.GetView I will try that and see if it works. The problem I have is that I have no idea what "Root" is or what it does, besides being part of the boilerplate code.

Edit 2: I guess If I replaced the name "Root" with "This" it makes more sense to what I am used to deal with from my own personal coding experience.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Edit 2: I guess If I replaced the name "Root" with "This" it makes more sense to what I am used to deal with from my own personal coding experience.
No.

Root is a member of the class instance. It is a simple panel that is used as the page's root view.

Could you be so kind to provide an example for doing it in each b4xpage_created event?
This code should work in every page.

There are more elegant ways to change the size of all views on all pages.

You can for example do something like:
B4X:
For Each pnl As B4XView In Array(Root, SecondPage.Root, ThirdPage.Root)
 
For Each b As B4XView In pnl.GetAllViewsRecursive
 If b Is Button Then b.TextSize = 18
Next

For this to work, you need to add the pages with B4XPages.AddPageAndCreate and to make the Root variable a public variable.
 
Upvote 0

calloatti

Member
Licensed User
Thank you again. Yes, by now I understood that you have to add and create the page to be able to do it for all b4xpages from B4XMainPage. I will add it to the create event of each page, since switching from addpage to AddPageAndCreate at this point in the app will be to problematic due to all the different things I set up in each page create event.

I will just add a sub to my generic helper code module and call it from each page_create event passing root to it. Thanks!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…