Then, we will add a ToggleButton that we will use for toggling between the metric system and the imperial system of measurements for weight and height. We will center the TextView horizontally by setting the “android:gravity” attribute to “center_horizontally”.
In the layout resource file for this Activity activity_main.xml, we will add the following user interface elements inside a LinearLayout with a vertical orientation.įirst, we will add a TextView inside the LinearLayout, that will display the title of the app as “BMI Calculator”. We will be using a single Activity for the BMI calculator app. See a sample of the styles.xml resource file that has removed the Action Bar below.
Once the Android project has been created, open the styles.xml resource file in the /app/src/main/res/values directory and update the parent attribute on the style element to value “” to remove the Action Bar from the Activity. Select the “Blank Activity” project template and provide a project name, set the package name then select “Finish” to create the Android project. Open Android Studio and follow the wizard for creating a new Android project. We will start this tutorial for building a BMI calculator by creating a brand new project in Android Studio. See the sample screenshots below for the Android app we will build. We will support both the metric unit system and the imperial unit system for calculating the BMI which allows the user to enter weight in either kilograms or pounds and the height in centimeters or feet and inches. In this tutorial, we will be creating an Android app that calculates Body Mass Index (BMI) based height and weight entered by the user. Creating a BMI Calculator Android App Tutorial Displays the calculated BMI and categorization of the BMI inside a CardView widgetĪll of the code samples shared in this post are available in GitHub.Uses a ToggleButton to support calculation of BMI with both the metric and imperial measurement systems.Contains a class that uses the Singleton Pattern and contains the calculation logic for BMI.Captures weight and height with EditText widgets.In this tutorial, we will build a BMI calculator app for Android that:
As a part of the series for creating apps from scratch, I have put together a tutorial on how to build a BMI calculator app for Android.