Breaking News

Build Your First Android App in Java



1 - Download and Install Android Studio : Android Studio
2 - Open Android Studio
3 - Click "Start a new Android Studio Project
4 - Name your app whatever you want
5 - Click "Next"
6 - "Phone and Tablet" helps you to set minimum Android Version, you can change it but leave the default value and click "Next"
7 - Choose Empty Activity and click "Next"
8 - Name your activity class or leave the default name and click "Finish"
9 - Wait until finishes
10 - Under project directory go to app > res > layout > activity_main.xml and write:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="@color/colorPrimary"
       android:orientation="vertical">

       <TextView
           android:id="@+id/textViewID"
           android:layout_width="match_parent"
           android:layout_height="50dp"
           android:text="Test Text" />

       <EditText
           android:id="@+id/inputTextID"
           android:layout_width="match_parent"
           android:layout_height="50dp"
           android:hint="type here"/>

       <Button
           android:id="@+id/buttonID"
           android:layout_width="match_parent"
           android:layout_height="20dp"
           android:text="Click" />

   </LinearLayout>

</LinearLayout>

11 - Under project directory go to app > java> com.android.app > MainActivity and write:

package com.android.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements View.OnClickListener {

    private TextView textView;
    private EditText inputText;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = (TextView) findViewById(R.id.textViewID);
        inputText = (EditText) findViewById(R.id.inputTextID);
        button = (Button) findViewById(R.id.buttonID);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if(view == button){
            String text = inputText.getText().toString();
            textView.setText(text);
            inputText.setText("");
        }
    }
}

12 - Now Connect your android device to your pc
13 - Click "Run" button
14 - Under "Connected Devices" choose your device and click "OK"
15 - Wait until Android Studio builds and installs the app into your phone
16 - Congratulations, you build your first Android App

Full Video:

No comments