Our aim is to develop an Android app where the background colour of the app is varied as in a red/blue strobe light. The background colour of the app will change from red to blue or vice versa each time we click a button located in the middle of the screen.

I named the app as “Lighthead app” as shown in Figure , but you can give any name you‟d like to.

Then, I selected the app to be compatible with phones and tablets having Android 4.0.3 (Ice Cream Sandwich) or later:

We‟ll have a simple screen therefore “Empty Activity” does the job in the next dialog:

Finally, leave the name of the activity as “MainActivity” and then click “Finish” to create the project files:

After the project is successfully created, the default view of the Android Studio will appear in which the middle pane will show the “MainActivity.java” file as shown below:

Developing the User Interface

Let‟s open the user interface layout file activity_main.xml where we will place the button on the screen.Let‟s open the user interface layout file activity_main.xml where we will place the button on the screen.Android Studio by selecting the Text tab as indicated by the arrow in Figure.

after follow above step just you see the following structure

When the Text tab is selected, the text format of the activity_main.xml file is displayed in the middle pane as follows:

we can see that our layout consists of a RelativeLayout structure, which begins by the line . Inside this layout, we have a TextView component. In other words, a TextView component exists inside the RelativeLayout component.

An Android GUI should consist of at least one layout class. For example, our activity_main.xml file has the RelativeLayout as shown in Figure


 We can build any GUI by using the subclasses of the View class shown in Figure

After deleting the default TextView, please find the Button widget from the objects palette and then drag and drop it in the middle of the GUI by the help of the guiding lines as shown in Figure

In this pane, one of the most important properties for accessing the button is the ID. All objects of the GUI of an Android app are accessed through their IDs in the coding part.

When we open attribute panel then we change all the setting according to the requirement .now we change the text on the button

Writing the Main Code of the App

We will do the programming in the MainActivity.java file. In order to open this file, navigate to the project explorer in Android Studio and then double-click on the MainActivity located under java

 com…..lightheadapp as shown below:

Opening the MainActivity.java file in Android Studio

You can open these codes by clicking on the … there as shown below:

And write the following code on the .java file of the application and run it

Run the above app and see the change .And Our first app will be completed.

Leave a Reply

Your email address will not be published.