Home  >  Java  >  Make Your First Android App Using Java And Xml

So this project is based on Android App Development,

Get Started With Android Studio

To make an Android app, you need an Integrated Development Environment (IDE), and Android Studio is the official IDE for creating Android Apps.

Create New Project in Android Studio.

Give your project a name and give it a unique package name too. Then, choose the minimum SDK you want to support with your app.

As it says beneath the Minimum SDK bar, with each API level, the features that you can use in your app increase. However, your app will run on fewer devices. The Create New Project dialog includes an estimator for the percentage of devices your app will run on.

The Image May Subject to Copyright.

After that You will be asked to select the layout of your application. Let's us choose the Empty Activity so that we have a lot to learn and experiment.

The Image May Subject to Copyright.
Once you give your activity a name —
Let’s name it as MainActivity for this tutorial,
Android Studio will take a moment to create your first project. Now, you have in front of you the main code editor where you will be able to write the code for your application.

The Image May Subject to Copyright.

The big section on your right side is the Editor Window, where you can write the code of your app. On your left side and below that are the tool of windows. This let's you to navigate easily and work on a specific task of your projects, for example browsing files or viewing debugging information.


The two bars that you see on top are the Toolbar, which allows you to perform common tasks in Android Studio, like building, running, and debugging apps, and the Navigation Bar, which lets you to navigate through the projects and the currently opened class files.


You Just take a few minutes to study the screen. It will make more sense for you to start making an Android application using Java.


Now it's time to finally make your first Java Android app.


Java Android App Development (.apk)

Now, if you look at the left side of your screen, you will see two folders. One of them holds your application's code and is named after the title of your project. In this case, it would be MyFirstJavaApp. The other folder contains Gradle Scripts, which is a free tool in Android Studio uses to turn your application's code into .apk files.

First of all click on it, to open the MyFirstJavaApp folder and access the code of your application. Then, click on the app folder. This has three folders which hold different elements of your project: manifests, java, and res.

To start, select res, which contains a file called activity_main.xml. Clicking on this file will allow you to access the layout of your main Activity. On screen, it will look like this:


The Image May Subject to Copyright.

The empty Activity that we chose has a ConstraintLayout, which is the root of the hierarchy, as you can see on the screen. It has just one element, TextView, that says Hello World. The constraint layout is a container for the components of your Activity and helps keep them spatially organized.


You have two basic ways to make changes to your Activity layout :

1. Edit the layout .xml file with the graphical user interface. You can drag and drop any elements of your choice to create your app. This is the default option and is accessed with the Design tab at the bottom of the window.


2. You can also edit the layout .xml file directly by clicking on the Text tab. Here, rather than dragging and dropping the elements, you write the layout code for your app from scratch.


The first method is great for you if you do not have much experience with writing code and your focus is learning to make a Java app using Android Studio. However, if you love to write code and want to get better at writing apps, the second method would be your way to go.

Make some Changes in Your App

Now you have myriad options open. Let’s experiment with changing the TextView a little. Open the code editor to see the code of TextView element which is going to look like this :

android:text="Hello World!"

Let’s change it to :

android:text="Envato Tuts+"


You can also change the text's color and the font style, but I am not choosing to do that here. However, I have putted the text in bold. Let's us run it on the AVD or the device to see how it looks like.


The Image May Subject to Copyright.

Here is the code for these changes :


Now, from the Design tab, let’s drag and drop a button to your app and change its text to Subscribe.


The Image May Subject to Copyright.

Here's the code this generates :


You can add various buttons and text to your app and allocate them a space using the constraints which you can access in the Design view.


Let's Make Your App more Interactive .


Up to this point, our app has a button, but it does not do anything when the user clicks on it. To make it interactive, we have to assign an action which will take place when a user taps on it. This is where we'll finally start writing some Java code.


Let’s say you want to tell users that they have successfully subscribed to the Envato Tuts+ newsletter. So, when the users click on Subscribe, you want them to see, Welcome to the Envato Tuts+ Newsletter.


Here’s how you will write the code :



And this is how it will look in the AVD :


The Image May Subject to Copyright.

Remember that each button that you add to your app has a specific id to help you refer to it from Java code.


Frequently Asked Questions

Q 1: Can I use this Source Code without giving credits ?

Ans: Yes, you can use but if your bring this projects, then should give us a credit at footer, because it takes alot time make all thess kinds of projects now if you ask that I want to bring it online but I will not give any credits to the developers & the provider then it is very wrong.

Q 2: Actually I want to bring this project online but I don't want to give credits ?

Ans: Ok, we have problem but also you cannot claim that it is made by you.
It is not all about flex you should increase you knowledge.

Q 3: If I am bringing this project online and not giving credits & claiming it is developed by me then ?

Ans: Ok, 1-3 times you will be warned and your that site will be suspended.
Still if you continue, then it can become to a legal things.

3 Comments

Gill

August 17, 2020 at 12:07 am Reply

Nice Work

Honk

Sep 04, 2020 at 5:30 pm Reply

WOW !!

OG

Dec 09, 2021 at 10:48 am Reply

nice !

Leave a Comment

Your email address will not be published. Required fields are marked *

Name *
Email *