Day 1 : Introduction to Android

2 min read

Dear Friends We gonna start with Introduction to Android OS , Android Studio and development tools that are needed to develop those creative applications which are loved by millions.

 

Today is the first day of this tutorial and in subsequent blog post there will be other topics on which we would be having brainstorming sessions.

 

We will be having a targeted approach in our studies so below are the topics we gonna cover.

  • Creating a simple Application in Android that accepts a simple string and prints that string on Screen.
  • Change the color of the background to some other color than white.
  • Put simple translation animation to the string.

Lets start with tackling first one

  • Creating a simple Application in Android that accepts a simple string and prints that string on Screen.

Start a new project in Android Studio .. put relevant details .. do what android prompts to you.

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);
    }
}

 

So thats how our first activity called MainActivity can be created. Please pay attention to the fact we are extending our MainActivity from AppCompatActivity and not Activity.  We are doing this because we want our final application to be backward compatible (means application that can run on older devices).

Lets play with our application and try to run it on actual device.

IMG-20160701-WA0044.jpg

 

You see we just have a ubiquitous “Hello World” single string displayed when our application is first launched in device.

  • Change the color of the background to some other color than white.

open colors.xml in you Android Studio for the project.

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>

 

You can add custom color  like this inside <resources> …. </resources> tags.

 <color name="customBg">#00ff84</color>

 

Now open activity_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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"/>
</RelativeLayout>

 

use background attribute for the top level RelativeLayout so that our activity will be having custom background.

android:background="@color/customBg"

 

And thats how our output will be like
image

 

  • Put simple translation animation to the string.

Now we will go ahead with playing with our simple application by putting a simple application to our string.  So that whenever activity is launched on device our string will appear animating from left to right.

For this to work properly we need to some ground work.

create a folder name ‘anim’ inside res directory.  Create xml file in anim directory.

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:fromXDelta="-100%"
        android:toXDelta="0%"
        android:fromYDelta="0%"
        android:toYDelta="0%"
        android:duration="1500" />
</set>

 

Now some changes to our MainActivity and associated view (activity_main.xml)

MainActivity

 

public class MainActivity extends AppCompatActivity {


    TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = (TextView)findViewById(R.id.strTv);

        Animation a = AnimationUtils.loadAnimation(this,R.anim.from_left);
        tv.startAnimation(a);


    }
}

 

activity_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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@color/customBg"
    >

    <TextView
        android:id="@+id/strTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"/>
</RelativeLayout>

 

And finally now build your code run it on device and enjoy your first ever android application.

output : Video

 

 

And At last but not the least Home work :

Build a simple Login Screen UX in Android Application.

 

Cheers ! Lets have a party.