In this blog we will learn how to create an application in Android Studio. This tutorial is designed for absolute beginners in Android development. First, open Android Studio and create a new project. When prompted, select the type of activity for your application, and for this tutorial, choose the "Empty Activity" option, then click "Next."
Next, give your application a name and change the package name if necessary. You will also see the location where your project will be saved. In the next option, choose the programming language you want to use, and for this example, we will use Java. You will also select the minimum SDK, which determines the minimum Android version required to run your app. For this tutorial, we select KitKat, meaning users with Android versions older than KitKat won’t be able to run your app. After this, click "Finish" and wait for your project to be built.
Once your project is ready, you will see a folder named "Java" where all your Java files will be stored. Within this folder, use the package name you assigned, which in this case is "com.firstapp.app." You won’t need to interact with other folders as they are automatically generated. To add a new Java file, right-click the folder, click "New," then "Java Class," and give it a name.
Next, move to the "res" folder and inside the "layout" folder, you will find your layout files. This is where you will design the UI for your app. Any images and other resources should be placed in the "drawable" folder. To add an image, simply copy the image file and paste it into the "drawable" folder, making sure the file name is in lowercase letters and adheres to naming conventions. Once the image is in place, you can drag and drop an "ImageView" from the palette onto your layout.
To resize the image, go to the attributes panel and set the layout width to "match_parent" and the height to "300dp." Make sure to add constraints to position the image correctly in the layout. You can do this by clicking the plus signs next to the view's boundaries to automatically add constraints. If you'd like to change the text in the "TextView," you can do so in the attributes panel.
To further customize the text, click the "Edit with Preview" option and adjust properties such as text size and style. For example, change the text size to "20sp" and make the text bold. You can view the layout in the preview window to check how it looks.
To run your application, select an emulator. If you don't have an emulator set up yet, open the "AVD Manager," create a new virtual device by selecting a device and Android version, and then click "Finish" to create the emulator. After that, close the AVD Manager, select the emulator, and click the play button to launch the app. The emulator will run the application and display the layout with the ImageView and "TextView" saying "My First App."
0 Comments