Android Studio Tutorial for beginners

In this tutorial I am going to discuss about Android Studio tutorial for beginners. People also asked about "Is Android Studio easy for beginners?" , "What are the basics of Android Studio?", "Is JDK required for Android Studio?" , "Which language is best for Android development?", "How can I create my own app?", "Where do I put code in Android Studio?". My answer for all these questions is YES.

If you are a beginner (Yes of course. that is the reason why you are here.) and wanted to learn it on yourself without depending much on others. When you got the basics of Android Studio then you can go to indeed by using only youtube tutorials. Then you need to use the technique of trial and error. It is quit time taking but that is the best way of learning where these concepts root in to your brain permanently. However you need to take a little help from internet if you are a beginner. Spend much time with your development in your basics. I also recommend you to have more friends who are like you in android development and converse with them and share ideas this leads to a great start and provides good learning environment.Refer this article and you will learn about Android Studio from zero to hero.


How to install android studio on windows for android developers ? 

For the android studio beginners, I am going to tech you how to install android studio. it will be step by step. It is very easy and very simple. But the installation process can take a while. Very firstly you must know the performance of your pc. Your RAM, VGA and the space you have, like wise. After that read the following instructions carefully and get started. Okay let's start with step one.


Step 01 - Download JDK file and install it in to your computer | android studio tutorial for beginners

Very firstly you have to Download Java Development Kit and install it in to your computer. Screenshot in the below will help you to find the website. All you need to do is you must careful about your installation part. Because if you are not download the correct one you can get a trouble.So download the correct file.

android studio tutorial for beginners - JDK file download
Android studio beginning - JDK file download

Step 02 - Download Android Studio setup on developer.android.com to get started

After installing the JDK file, have to Download the Android Studio Setup. In the below you can see the website that you are going to download Android Studio setup. It is developer.android.com site. So download the setup and go to step 03.

Android studio beginning - Setup download
Android studio beginning - Setup download

Step 03 - Install the Android Studio setup ( Run the exe file )

After downloading the setup, double click on it. Then click next. After that you can see a window to choose components that you want to install. You can choose Android SDK and the Android Virtual device, if your pc has better performance.

Android Studio beginning - Installing the setup exe
Android Studio beginning - Installing the setup exe

Please be careful. you don't have better performance, don't choose Android Virtual Device. You can connect you phone later as an Android Virtual Device. Because need a better performance to run the Virtual device.


Step 04 - Do the other installation parts to get started

After choosing the options, you can read all the license and terms that the android studio has. Then click the "I agree" button and select the installation folder. Then click install. This may take a while.  After that you can run android studio by clicking finish in the window.

Okay!! Now you installed the Android Studio. Let's get started by creating a new project.


Step 05  - How to create a new project in Android Studio | Last part of android studio tutorial for beginners

Open Android Studio first. Then you can see a window like this.

Create a new project
Android Studio - Create a new project

Don't care about the things in the left hand side of my screenshot. Those are my projects that I did previous weeks. So if you want to start a new project, click " + Start a new Android Studio project ". After that you can see a window like this. You can choose any activity yo want. Select one and go to next part.

Android Studio - Create a new project window
Android Studio - Create a new project window - Android Studio Tutorials

You can choose what ever the activity you want. I choose Empty activity and click next. Then you can see a new window like the screenshot given below.

Android Studio - Create a new project window 02

You can give any name you would like. Don't change the language. because I am going to give you android tutorials by using Java language. So don't change the language. If you want to learn kotlin (other language), you can refer anything.

After that select the minimum API level that you want. I am going to select 19. Then click finish.


Let's design a simple mobile application | Android Studio tutorial for beginners

Now you know how to create a new project in Android Studio. When you creating a new project, choose your project as an empty activity and the language is Java. So I am going to name it as "Simple Program". Very firstly, let's discuss what is a layout in Android Studio.


What is a Layout ?

Layout is the structure for a user Interface in a mobile application. It means the Layout is a master plan or a blueprint of the printed or published work that lays out the order of its various graphic elements. For more information refer the Android Developer site.

In Android, an XML-based layout is a file that defines the different widgets to be used in the UI and the relations between those widgets and their containers. Android treats the layout files as resources. Hence the layouts are kept in the folder res layout.

There is a number of layout classes in the Android SDK. They can be used, modified or can create your own to make the UI for your Views, Fragments and Activities. You can display your contents effectively by using the right combination of layouts. People also asked about "What are the layouts in Android Studio?" , "What is the difference between layouts in Android Studio?" , "Which layout is mostly used in Android?" and "Which layout is mostly used in Android Studio?". So let's discuss what are the examples for layouts in android. Constraint Layout , Linear Layout , Relative Layout , Grid Layout are the main layouts in android studio. Let's discuss briefly what are those,

  • Constraint Layout - This is the default layout. In this layout we can set margins by dragging the arrow witch is in the element's border.
Constraint Layout example
Constraint Layout example

To change the layout, right click on the Component tree and click "Convert view". For example see the image given below.

  • Linear Layout - This is the most usable layout. In this layout, we don't want to adjust the margins like in Constraint layout. Drag and drop some elements to the interface and see the different between Constraint layout and the Linear layout. A LinearLayout aligns each of the child View in either a vertical or a horizontal line. A vertical layout has a column of Views, whereas in a horizontal layout there is a row of Views. It supports a weight attribute for each child View that can control the relative size of each child View within the available space.
Linear Layout example
Linear Layout example
  • Grid Layout - This layout provides elements as grids. It was introduced in Android 4.0 (API level 14), the Grid Layout used a rectangular grid of infinitely thin lines to lay out Views in a series of rows and columns. The Grid Layout is incredibly flexible and can be used to greatly simplify layouts and reduce or eliminate the complex nesting often required to construct UIs using the layouts described before. for example,
Grid Layout example
Grid Layout example
  • Relative Layout - In this layout user must set the margins and padding in the XML file. This is use to set the elements in a correct order in a single line. It is flexible than other native layouts as it lets us to define the position of each child View relative to the other views and the dimensions of the screen. 

What is a Palette In Android Studio ?

Palette is the tool which provides elements. It has buttons , text elements , Widgets , Layouts etc. You can choose what ever you want to design your mobile application. What you need to do is, drag and drop the elements on to your interface.

What is a Palette In Android Studio ?
What is a Palette In Android Studio ?

Let's design a simple mobile application | Android Studio tutorial for beginners

So, see the image given below. I designed that layout using Constraint layout.

I designed that layout using Constraint layout.
I designed that layout using Constraint layout.

In here my design surface is Blueprint. Don't worry you can change it as Blueprint or Design or both. To change it,

change the design surface
change the design surface

Quiz 01 - Try to do the same interface in the above, using  Linear Layout.

If your a master in coding or do you like to do coding without drag and dropping, you can got to activity_main.xml file which is in "layout" folder in "res" or "resource" section.

resource section to find the files
resource section to find the files
  • Other options

In this section you can find what ever files in your android project. Do you want to see the java file, go to Java section. Do you want to see the images you have in your project, go to drawable folder under "res" or "resource" section. Android manifest file is in the manifests section.

  • Let's go back to "Let's design a simple mobile application"

Double click the Activity_main.xml file and open it. you can see the interface design section. to do the coding part you have to choose the "Text" part in the below of the activity_main.xml file. see the example given below.

change the type in xml file
change the type in xml file

So, if you want to run your application, click the play button on in the top of the files. see the image given below.

to run the application

After that the system will display a window like this.

set development target interface
set development target interface

Android Fragments | Android Studio tutorial for beginners

What are Fragments and Why are fragments used in Android applications?

According to the Android documentation, a fragment is a part of applications user interface that is bound to an activity. Fragments have their lifecycle and layouts or UI components. Fragments help enrich your UI design, pass data between different screens, and adapt to different device configurations.

Have you heard of a concept called one page design? It's as the name suggests, it is having one view and swapping content in and out, and that is what fragments are for. The main view is held in an activity while that activity behaves like a wrapper, it allows you to swap view screens 'fragments' removing the need for opening up an activity for every action.

Activity and fragment difference is huge but sometimes small.

  • An activity is basically a page or working part of your app. You have a Java class for it and XML to setup display and events of a page. For instance a login page. Once you login the login activity will switch to another activity and this activity will cover the last activity. The activities are like pages one comes over another completely. An android app is a collection of these activities you might say.

  • Fragment is a part of activity in simple words. Just like activity you can switch fragments from one to another. Now you will ask why do we need them. Well let me give you a question. There is an activity divided into two parts one part has three buttons and other has blank space. On clicking first button textbox appears, on second image view and on third again a blank. Now you could design this using activity but switching and overheads will be great. Instead use fragments divide activity in two. And switch fragment on click. It reduces overhead why because when switching fragment in parent the information need not be transferred via intent simply parent activity the main activity can be made to hold data.and fragment can use it.

What are the important point of Android fragment

According to Quora,

  • A fragment has its own layout and its own behaviour with its own life cycle callbacks.
  • Fragment life cycle is closely related to the life cycle of its host activity which means when the activity is paused, all the fragments available in the activity will also be stopped.
  • You can add or remove fragments in an activity while the activity is running.
  • You can combine multiple fragments in a single activity to build a multi-pane UI.
  • A fragment can be used in multiple activities.
  • A fragment can implement a behaviour that has no user interface component.

So let's create fragment in android studio. Very firstly we want a new project to create fragments. Follow the steps in the below.

  1. Start a project name "Android Fragments".
  2. I am going to change the layout from Constraint layout to Linear layout. For that go to activity_main.xml file and right click "ConstraintLayout" from the component tree. Then click "convert view" and select "Linear layout" from the list. After that click apply.
  3. Right click on the linear layout from the component tree again and change the orientation to vertical.
"<yoastmark

Get new fragment layouts - Android Fragments - Android Tutorials

For that right click on the layout folder and go to new tab. Then find the fragment in the below and click fragment (blank) option. After that name it as "fragment 1". So in here I am going to change the background color as red.

To that go to fragment_fragment_1.xml file which is the layout file for the first fragment and select the design surface a s "Design". Then go to attributes and change the background color to red. ( you can search as background to find the attribute ).

fragment 1 - Get new fragment layouts - Android Fragments
fragment 1 - Get new fragment layouts - Android Fragments

Next I am going to repeat the above step to create a another fragment layout called "fragment 2" and change the background color as green ( fragment_fragment_2.xml file ).


Design the activity main XML file - Android Fragments - Android Tutorials

Finally we want a main interface to display fragments. For that go to activity main XML file and add two buttons like this.

After that add a fragment view below the two fragment buttons. Fragment view can be found from the palette. When you drop the fragment view, you will be ask to select the default fragment. So select the fragment 1 as the default fragment.

After that change the layout height to "match parent". It means from end of two fragment buttons to below of the screen. You can rename the id as you like. In here I am going to rename it as "fragmentDefault".

So the designing part is over. Now I am going to implement the methods to view fragments when the buttons are clicked. For that go to main activity java file to implement it.


Implement Java class - Android fragments

Very firstly go to fragment java classes and delete all the codes within the two fragment classes keeping only "onCreateView" method. Because we don't need those methods and we only need this onCreateView method. Because we are going to display fragments when the buttons click.

Implementation

In here I implemented two if conditions. because we have two fragments two display when the buttons click. So in the first if condition I found the button id using the "findViewById" keyword. Then I create a new object in Fragment. After that I implemented those code for display fragment 1.

In the next if condition I did the same thing when I done in the first if condition to display the fragment 2.

Finally, go to activity main XML file and go to the attributes bar. Then search onClick method and change it in to "changeFragment" on both two buttons. Then run the program and see the output.


Okay that's all for today. If you have any trouble, comment below. I will reply soon as possible. This is the end of "Android studio tutorial for beginners" article. If you are a newbie to Android. Follow and refer articles. Click below link to get started.

Other articles from different categories.

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x