In the previous article, we learned how to create a shared library. In this post, you will learn how to use that library in an android application to display a message – “Applications running on: Android”.
In an Android application, we define the UI components in the XML file and we use Activity to render those XMLs where we can also specify the actions we want to perform on those UI elements.
Based on our previous post Build Android app, our UI components are present in the file activity_main.xml file in the MultiplatformApp folder ( to find the file: double-tap shift button and search). Add the TextView into the file that displays the text in the devices.
Make sure that you specify the id, width, height, and constraints to specify the layout of the view as shown in the above snippet . This TextView will be used in the MainActivity.kt to give the real text value which we will get from the Shared Library.
In the MainActivity, add the following line of code.
Note that the getMessage() is the function we obtained from the Shared framework which returns us a platform name. Run the application and your result should be similar to the diagram given below.
In this tutorial, you learned how to add the UI element and use them in the Activity(UI screen) in Android. We will build a similar application in IOS in the next post.
No responses yet