Android Tutorial [B4X] Sharing layouts between platforms

Sharing code between the platforms is quite simple with the reference modules feature: https://www.b4x.com/android/forum/threads/b4x-modules-files-groups-and-folders.86587/#content
Once you learn how to use XUI library with B4XView and the various cross platform controls you can share 95%+ of the code and use conditional compilation or platform specific modules for the other 5%.

Sharing files can be done with a CustomBuildAction as explained here: https://www.b4x.com/android/forum/threads/xui2d-cross-platform-tips.96815/#content

Starting from B4A v9.50, B4J v7.80 and B4i v6.00 it is possible to "share" layouts between the platforms.
The three tools now support copying and pasting controls.

tSMBhiL6kb.gif


This allows you to build the layout on one platform and later copy all of it or parts of it to other platforms.

Each platform has unique controls. These cannot be copied. The same is true for unique properties that are not available in other platforms.
Custom views, and especially custom views that are built over XUI and are intended to be cross platform (example: XUI Views), can be shared with all there properties.

It is also possible to declare views as B4XViews directly from the designer. Note that custom views do not need to be declared as B4XViews. Then should be declared with the custom type, which is cross platform.
Tip: you can always cast B4XViews to the explicit type and vice versa.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The following types of views can be copied between the platforms:
  • CheckBox / Switch
  • Button
  • Label
  • Panel
  • ToggleButton
  • SeekBar / Slider
  • Spinner / ComboBox / ChoiceBox (B4A and B4i only) - better to use B4XComboBox from XUI Views.
  • ImageView
  • ProgressBar / ProgressView / ProgressIndicator
  • RadioButton
  • EditText / TextView / TextField / TextArea
  • WebView
  • Custom Views

Using cross platform views such as the views in XUI Views make it easier to develop cross platform solutions.

XUI Views includes the following cross platform views:

  • B4XComboBox - Cross platform ComboBox / Spinner / ActionSheet.
  • ScrollingLabel - A label that scrolls the text when it is wider than the label.
  • AnotherProgressBar - Vertical or horizontal animated progress bar.
  • B4XLoadingIndicator - 6 different animated loading indicators.
  • RoundSlider - A round slider.
  • SwiftButton - 3d button
  • AnimatedCounter
  • B4XFloatTextField - A TextField / EditText with a floating hint
  • B4XSwitch - Nice looking two state control.
  • B4XPlusMinus - Allows the user to select a number or item from a previously set list.
  • B4XBreadCrumb - Navigation control.
  • B4XSeekBar - Horizontal or vertical seek bar / slider.
And dialogs:
  • Plain dialog.
  • Custom dialog.
  • B4XDateTemplate - Date picker.
  • B4XColorTemplate - Nice color picker.
  • B4XLongTextTemplate - Scrollable text.
  • B4XListTemplate - A list of items. The user can choose one of the items.
  • B4XSignatureTemplate - Captures the user signature and adds a timestamp to the bitmap.
  • B4XInputTemplate - Template for text and numeric inputs.
  • B4XSearchTemplate - A list with a search field. An evolution of SearchView.
  • B4XTimedTemplate - A template that wraps other templates and creates a dialog that closes automatically after the set time with a nice animated progress bar.
Check B4XPreferencesDialog if you want to implement cross platform input forms:

firefox_GySNSOxWhb.png
 
Last edited:
Top