iOS Question How to set a background image on a B4XPages

giagia

Member
Licensed User
is possible to set a background image on a B4XPages ? what is the code without use designer? in B4a is Activity.SetBackgroundImage(LoadBitmapSample(File.DirAssets,"homepage.png,width,heigth)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
in B4a is Activity.SetBackgroundImage(LoadBitmapSample(File.DirAssets,"homepage.png,width,heigth)
Not good. Don't write platform specific code unless you must.

The correct way to do it is to add an ImageView to the layout, anchored to all sides and set the image. You can then just copy the view between the layout files (in the different platforms).
 
Upvote 0

giagia

Member
Licensed User
Not good. Don't write platform specific code unless you must.

The correct way to do it is to add an ImageView to the layout, anchored to all sides and set the image. You can then just copy the view between the layout files (in the different platforms).

Erel can you post an code example ? Im not using the designer to create a layout
 
Upvote 0

giagia

Member
Licensed User
This is a mistake in B4A, a very big mistake in B4i and a huge mistake if you are building cross platform solutions.
Many things will become very complicated.

Start with B4J / B4i resize event video tutorial: https://www.b4x.com/etp.html
I need to change background image when I have same conditions. For this reason I can't use Visual designer to set a fix image.
 
Upvote 0

AnandGupta

Well-Known Member
Licensed User
Longtime User
I think you can easily change the image on condition once you set the image view in designer.

Regards

Anand
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
If you want to set 'solid' background, you need ImageView (with lowest z-order).

But if you need a pattern (repeated image), you can set it like color.
B4X:
Dim nativeObjectPattern As NativeObject
nativeObjectPattern = nativeObjectPattern.Initialize ("UIColor").RunMethod ("colorWithPatternImage:", Array (LoadBitmap (File.DirAssets, "background.jpg")))
Dim nativeObjectRoot As NativeObject = Root
nativeObjectRoot.SetField ("backgroundColor", nativeObjectPattern)

IMO, to make a code more readable, platform specific code is better to hide in own b4xlib.
 
Upvote 0
Top