Published using Google Docs
101 Android Studio Create New Project
Updated automatically every 5 minutes

101 Android Studio Create New Project

This tutorial is based on the official tutorial at http://developer.android.com/training/basics/firstapp/creating-project.html .

This tutorial was done with Android Studio 1.4.

1) In Android Studio, create a new project.

File/New/Project...

1.1) Configure your new project.

1.2) Select the form factors your app will run.

1.3) Select Blank Activity.

1.4) Customize the Activity

1.5) Click Finish.

2) Your Android project is now a basic "Hello World" app that contains some default files. Take a moment to review the most important of these:

2.1) res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

   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" android:fitsSystemWindows="true"

   tools:context=".MainActivity">

   <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"

       android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

       <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

           android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"

           android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

   </android.support.design.widget.AppBarLayout>

   <include layout="@layout/content_main" />

   <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

       android:layout_width="wrap_content" android:layout_height="wrap_content"

       android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

       android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

2.1.2) res/layout/content_main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

   xmlns:tools="http://schemas.android.com/tools"

   xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

   android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

   android:paddingRight="@dimen/activity_horizontal_margin"

   android:paddingTop="@dimen/activity_vertical_margin"

   android:paddingBottom="@dimen/activity_vertical_margin"

   app:layout_behavior="@string/appbar_scrolling_view_behavior"

   tools:showIn="@layout/activity_main" tools:context=".MainActivity">

   <TextView android:text="Hello World!" android:layout_width="wrap_content"

       android:layout_height="wrap_content" />

</RelativeLayout>

2.2) MainActivity.java

package com.notarazi.myfirstapp;

import android.os.Bundle;

import android.support.design.widget.FloatingActionButton;

import android.support.design.widget.Snackbar;

import android.support.v7.app.AppCompatActivity;

import android.support.v7.widget.Toolbar;

import android.view.View;

import android.view.Menu;

import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

   @Override

   protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

       Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

       setSupportActionBar(toolbar);

       FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

       fab.setOnClickListener(new View.OnClickListener() {

           @Override

           public void onClick(View view) {

               Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)

                       .setAction("Action", null).show();

           }

       });

   }

   @Override

   public boolean onCreateOptionsMenu(Menu menu) {

       // Inflate the menu; this adds items to the action bar if it is present.

       getMenuInflater().inflate(R.menu.menu_main, menu);

       return true;

   }

   @Override

   public boolean onOptionsItemSelected(MenuItem item) {

       // Handle action bar item clicks here. The action bar will

       // automatically handle clicks on the Home/Up button, so long

       // as you specify a parent activity in AndroidManifest.xml.

       int id = item.getItemId();

       //noinspection SimplifiableIfStatement

       if (id == R.id.action_settings) {

           return true;

       }

       return super.onOptionsItemSelected(item);

   }

}

2.3) AndroiManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

   package="com.notarazi.myfirstapp" >

   <application

       android:allowBackup="true"

       android:icon="@mipmap/ic_launcher"

       android:label="@string/app_name"

       android:supportsRtl="true"

       android:theme="@style/AppTheme" >

       <activity

           android:name=".MainActivity"

           android:label="@string/app_name"

           android:theme="@style/AppTheme.NoActionBar" >

           <intent-filter>

               <action android:name="android.intent.action.MAIN" />

               <category android:name="android.intent.category.LAUNCHER" />

           </intent-filter>

       </activity>

   </application>

</manifest>

2.4) build.gradle (Module:app)

apply plugin: 'com.android.application'

android {

   compileSdkVersion 23

   buildToolsVersion "23.0.1"

   defaultConfig {

       applicationId "com.notarazi.myfirstapp"

       minSdkVersion 14

       targetSdkVersion 23

       versionCode 1

       versionName "1.0"

   }

   buildTypes {

       release {

           minifyEnabled false

           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

       }

   }

}

dependencies {

   compile fileTree(dir: 'libs', include: ['*.jar'])

   testCompile 'junit:junit:4.12'

   compile 'com.android.support:appcompat-v7:23.1.0'

   compile 'com.android.support:design:23.1.0'

}

OUTCOME

Later on when you run this app, it will look like below.

The look is actually defined by the codes in activity_main.xml and content_main.xml

DOWNLOAD

MyFirstApp.zip