Hello people. Today we will move on to actually developing apps.
⚠ I strongly recommend that you should first install the Android Studio IDE before moving ahead. You can get help on installing Android Studio from here.
Let us start with a simple implementation of the Activity Class.
Today we will make an app which will display “Hello YourName!” on the screen. Here you have to replace YourName by someone’s name.
⚠ Your user interface of the Android Studio may slightly differ from the one shown here depending upon the version of Android Studio you are using, but the functionality remains the same.
Step 1: Creating a new project
Open Android Studio and select create a new project option. In the next step enter the details as shown in the picture below.
You may alter the company domain if you want to. The project location will be automatically set by the Studio.
In the next step, select only the phones and tablet option, as we currently want to develop an app for a mobile phone only. The minimum API is the oldest version of Android OS on which your app will be able to run. Currently select all the options as shown in the picture below for the sake of simplicity.
You may want to support even older versions of Android OS, but then you will not be able to include certain features in your app which are only supported on the newer versions of the Android OS.
In the next step select the basic activity.
This option will provide you with a basic skeleton of an app, which you can edit to create your app.
In the next step fill all the details as they are shown in the picture below.
Click finish and wait for the Studio to complete the process of building the app.
Step 2: Editing the layout file to display your name
After the Studio has finished building your app the screen will look something like the one shown in the picture below.
As shown in the picture above the app will display the words “Hello World!” in the top right corner of your phone’s screen. Now we will edit the code in the layout file to display your name instead of “World” on the screen.
You can see the code behind this layout by clicking on the text tab at the bottom as shown in the picture below.
This is the code where the editing needs to be done.
Now in the TextView tag the “android:text” attribute determines the text to be shown on the screen. Change the value of that attribute from “Hello World!” to “Hello YourName” (which in this case is Shrey). Now your code should look something like the one shown in the next picture.
Now click on the design tab at the bottom to see your name displayed on the screen.
Do It Yourself:
As you can see the size of the text is very small and the colour of the text is also not very attractive. So I would like to leave it to you to increase the size & colour of the text.
Hint: Add the attributes “android:textSize” and “android:textColor” to the TextView tag. The text size should be defined in sp or dp units. You can get hexadecimal codes for colours from here.
For any queries or help just drop mail at firstname.lastname@example.org
We will add more functionality to this app in the next post. Till then keep experimenting with this app and keep coding.