
The developers each year create more and more applications for mobile devices, in this tutorial we will begin the knowledge to create applications for Android mobiles.
Android is a complete operating environment based on the Linux kernel, which is found on various mobile devices.
While the official software is Android Studio in this case we will use Netbeans for being lighter, while Android Studio requires a 4 GB ram of mine to work well, with Netbeans we can develop with 2GB of ram.
Before starting we will install the necessary software
Android SDK
The software development kit or Software Development Kit are the libraries to develop from an IDE other than Android studio or run the command line tools. These libraries provide the basic tools of the SDK for the development of mobile applications. We can download Android SDK from the official website. For this tutorial we install the Linux version but can be installed on Windows, Linux or Mac.
We download the zip file and then unzip the .zip file and copy the folder with the SDK files to an accessible folder specified by the user for example / opt / Android /.
Netbeans
It is a free IDE, designed for programming in Java, which was later extended to other languages such as HTML5, C ++, PHP. There is also a significant number of plugins developed by the community to extend it. NetBeans IDE is cross platform and free. We can download it from the Netbeans IDE website.
It can be installed from Linux, we go to the directory where we download them and write with the following commands:
cd Downloads sudo chmod + x netbeans-8.0.2-linux.sh sudo sh netbeans-8.0.2-linux.shWe go on to configure it.
Configure Netbeans and Android SDK to run and compile applications
Once we have installed both software we will follow the next steps, open Netbeans and go to Tools> Plugins, go to the Settings tab and click on the Add or Add button.
Next we add the url //nbandroid.org...tes/updates.xml, and put the name of the plugin. We have it checked automatically for plugin updates.
Then we accept and we will see that the plugin appears in the list of the Update Center .
Next we must go to Tools> Options and indicate on the Android and Mobile Plataform tabs which is the path to the Android SDK which is the folder where we install them.
/ home / myuser / Android / Sdk
Next we must configure and install the version of SDK we want to use, for them we go to the Tools> Android SDK Manager menu. This configuration is the same that we use in the tutorial Programming on mobile devices with Android.
This will allow us to select and install the sdk versions for example we have Android 4.4.2 KitKat, Android 5.0 and 5.1.1 Lollipop installed.
After installing the versions that interest us we must create a virtual device for this we go to the Tools> ADV Manager menu .
Then we click on Create and configure the characteristics of the test mobile phone, it is clear that the newer version is the more ram we will need to emulate the device.
We can configure the devices and screen, the type of processor, the android version, the camera, the available RAM and the microSD card. We accept and we will have our device ready to use, if we want to try it we can click on Start, but it will be activated when we compile the application with Netbeans .
Next we will develop some sample applications to take our first steps in the development of native Android applications .
Designing the graphical interface of Android applications
The design of an Android application that is the Layouts that are the screens that we see in the application. A Layout is an element that defines the design of the user interface, they are component containers and views to define the visual format, the Layouts are defined by XML and the functionality is assigned by referencing and programming them with Java.
There are 4 types of Layout that we can use on Android and they are the following: $config[ads_text5] not found
Linear Layout
This type of design aligns all components in one direction, vertically or horizontally.
RelativeLayout
It is a layout that adapts to the screen using relative positions. The position of each complement can be defined as in relation to the elements distributed on the screen.
ListView
It is a layout that shows a list of components and elements. It is used to display a list of options or for example a list of contacts. $config[ads_text6] not found
GridView
It is a layout that presents a grid with rows and columns. The components are added from the grid using a ListAdapter.
For an introduction to how views can be inserted dynamically using an adapter, read Construction designs with an adapter. $config[ads_text5] not found
We develop an example with LinearLayout
We start by opening Netbeans and go to File> New Project and add an Android project.
Next we define the name of the LayouLineal project, the name of the Java package will always be com.applicationname, in this case it will be com.Lineal, and then the name of the main class of the Android application, in this case Linear.
The structure of the Android project is divided into several folders:
- Source Packages: where our class and Java code goes, which will give the application functionality.
- Resources: where will be the resources that we will use in our application, images, audios, videos.
- Layout: where each xml file that represents a screen is located.
In this example we will design a login application, which will have the following interface:
We start by designing the interface, go to Resources> layout, inside we will see the default screen main.xml, to which we will add the following code.
The layout configuration parameters are:
- Match_parent: which means that the layout should be as large as the screen
- Wrap_content: which means that the layout must be so large to enclose all the components we have can exceed the screen size, for example a list.
Then we set the severity or type of flotation, it can be vertical centered or horizontal centered, the code is as follows: We use the background property to reference the folder and the name of the image to use that we previously added to the drawable-mdpi folder an image that we will use as the background of our application.
Our selected image for the background has a size of 1280px wide and 800px high we can use any image, in this tutorial we use the following:
Then we will see the Java code, for this we go to Sources Packages and select the Lineal.java file, we can see that it creates and shows the content of the main layout screen that is the xml that we wrote above.
package com.Lineal; import android.app.Activity; import android.os.Bundle; public class Linear extends Activity {public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.main); }}Then we run from the Run> Run Project menu, the Android device will start and we will find the Linear application installed on the device and execute it by clicking on its icon.
Next we will add the components for our application in the area where we put the comment.
We add the LOGIN text and its padding properties is the left space and upper the syntax is After the previous component we will add User text and a text box or EditTExt within a row for this we will use a linear layout Next we will add another component a TextView and an EditText for the Key Next we will add a Login button We can see that the properties with them for all components, that is, we define the margin from the edge of the screen, the space from the edge of the component inwards, the text of the component.
Next we will run and see the components in the application.
Now we have to compile for this we go to the Run> Build Project menu, this will compile the apk file to install on Android or upload to the Google PlayStore store.
In the bin folder of the project we will find the file LayouLineal-default.apk, we can rename it, removing the word default.
Finally to install on the phone and try we can connect it via USB and copy it to the Downloads folder of our phone.
In a next tutorial we will continue with Layout and the programming of functionalities.
- 0
Articles