In this tutorial we will see how to create Hello World application in android using Android Studio. Here we will use TextView widget and print Hello World message.
To begin with Hello World application start Android Studio and you will see message Welcome to Android Studio message. We will create new application so we will select “Start a new Android Studio project”.
Now you can see many small activities. To begin with we will select Empty Activity and press Next. This will create new blank Activity.
Now enter you name in Name box. Example – Hello World
Click on Finish button once done.
Once you created an application two files will be generated.
MainActivity.java is a class file in which you will write java program.
package com.techstackguru.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
This is activity_main.xml file, here we will write code rated to xml. Below we are using TextView widget and will display Hello World! message.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:p="Hello World!"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Run an application with Run button as displayed in an image
Select an Available Virtual Devices