- How to Make Android Apps for Beginners
- How to Make an App in Java
- Run Android Studio
- Start Working on Java App Development
- Modify the App Layout
- Add Constraints
- Assigning Activity to the Button
- Conclusion
- Android App Templates and UI Kits From CodeCanyon
- Getting Started With Android Studio
- 1. Project Setup
- 2. Android Virtual Devices
- 3. Live Layout
- 4. Templates
- 5. Lint Tools
- 6. Rich Layout Editor
- Conclusion
How to Make Android Apps for Beginners
Are you a new developer learning Java? Read ahead to learn how to make your first Java Android app as a beginner.
Creating a mobile application is a big step towards turning your idea into reality. But the primary concern among new developers is how to make an Android app with all the resources at their disposal. If you’re a beginner, you won’t know the purpose of many of them. So it’s important to begin from the basics and know the starting point.
This guide will walk you through the basics of building an Android app and answer your questions about how to make an app with Java. We’ll be creating a Java Android app using Android Studio as our Integrated Development Environment (IDE).
How to Make an App in Java
To start making a Java Android app, you have to start with an IDE. There are several options for IDEs, but two of the most efficient ones are Eclipse and Android Studio.
For this guide, we are using Android Studio 3.1.3. Android Studio is a complete IDE that offers tools to make app development very simple and easy. It has an advanced code editor and several app design templates. There are tools for development, debugging, and testing as well.
You can learn how to install Android Studio in our post on how to get started making Android apps.
Run Android Studio
Let’s begin with a new project on Android Studio. It gives the option to Create New Project on the welcome screen. You can also continue with your current project if you have one.
Once you choose to create a new project, the next step is choosing your activity. You will be provided with several options, but we’ll begin with an Empty Activity for this tutorial on creating a Java app.
The next step is configuring your activity by giving it a name. Let’s name our app MyBasicApp. From the drop-down menu, choose the Java language. Click Finish.
Now we are ready to start creating our app!
Start Working on Java App Development
At this stage, Android Studio has created two folders that are visible in the left corner. They are:
- A folder for MyBasicApp—this folder carries the code for your app.
- A folder of Gradle scripts—Gradle is a free and open-source tool used by Android Studio to turn the code into an .apk file for your app.
Since we selected the Basic Activity template, Android Studio has created some preset files for our project. You can expand the folders to view them.
Clicking on the app folder will give a drop-down menu with three to four subfolders: manifests, Java, Java (generated), and res. Expanding each one of them will open more folders. Each folder stores a separate component of your project.
In the MyBasicApp folder, go to the Java folder and click on com.example.mybasicapp. This folder contains the source code of your Java Android app.
Now, click the res folder and open the layout folder. It contains a file activity_main.xml. It is the layout of your app. Click to open it.
Now your project view has opened the source code and the layout in two separate tabs. It looks like this:
The .xml file gives you a layout where you can drag and drop elements to build your file. You can also change it to code editor by clicking on text at the bottom left corner. Now you can edit the source code instead of adding elements to the design layout.
In the layout editor, the left pane contains all the elements that you can add to the layout. If you see the component tree, there is just one element—Hello World—in our app.
The elements we add to our layout will be shown in the component tree and how they are added in relation to each other.
Here, ConstraintLayout is the root of the view hierarchy (it is the dimensions of the page on which components will be added).
The ConstraintLayout has a TextView called Hello World.
The TextView is the component that came with a blank activity. The layout at this stage looks like this:
The XML code for this layout will be this:
It has one root hierarchy with just one text element.
Note that this is the basic layout that Android Studio generated itself. We haven’t made any modifications to it yet.
Modify the App Layout
The next step is to modify the layout by adding components of your choice and associating activities with them.
Here you can either start with this ConstraintLayout with TextView in it, or you can clear the ConstraintLayout and begin with a clean slate in terms of layout.
Let’s say you want to change the text on the TextView . You can go to the code editor and view the properties of the TextView element. The code will be like this:
Change the string to whatever you like. For now, I’ll stick with Hello World.
If you have set up an Android Virtual Device (AVD) in the Studio, the app will run on the simulator like this:
This is the basic TextView with Hello World! as its string. You can modify the attributes of this text component. Edit the text, font, size, and color to give a new look to TextView .
The XML code for these changes would be this:
We have changed the font to Sans Serif and made the color darker gray . The font size is also increased to 30sp , and the text is made bold.
The changes as visible in the AVD:
Add Constraints
Up to now, we’ve just modified the stock Empty Activity set up by Android Studio. Now, we will see how to add constraints and views to the user interface.
In the Layout Editor, there is a palette on the right side from where you can choose the constraints you’d like to add.
You can add more than one view and constrain them to top, bottom, left, or right. These views have attributes that can be edited to modify them.
To better understand what an attribute is, select textView in the Component Tree and look at the Constraint Widget in the Attributes panel.
The square represents the constraints.
The rectangular box and each of the four dots represent a constraint. You can increase or decrease their value based on the point where you want to place the view.
Here is how it looks in the Layout Editor.
You can drag and drop the Views from the left palette to add them in the ConstraintLayout . After adding them, you can apply constraints to determine their position. Each new button added to the layout is given a unique identity.
Here is how your layout will look after adding the constraints to the views:
Here is the XML code for the finished layout:
Assigning Activity to the Button
The layout design is the meat of your app. You have added a Button , but it doesn’t do anything when pressed. To make it interactive and responsive to users’ actions, we have to assign activity to it.
Let’s say this is the last step on your app, and upon clicking Next you want people to see the message Finish. Here’s how to do it.
The Next button has an id called @+id/next . Since no other element is using this id, we can use it to find the button and add it to the Java code so that the activity doesn’t get associated with another button.
The id for a view helps you identify it as each id differs from other viewers’ id. With the findViewByID() function, next can be found through its id, R.id.next .
Here is the final code that will display the finish message:
Run the app to see how the Button works.
Conclusion
This guide covered everything from setting up the Android Studio to coding and testing a Button . It’s not hard to get started coding an app—Java mobile app development has become easier since a lot of elements are drag and drop.
Android App Templates and UI Kits From CodeCanyon
You may have noticed that our app looks very plain and simple. That’s because we’re using the default theme, without applying any styles to our views. CodeCanyon is full of Android UI kits that offer beautiful, hand-crafted styles you can apply to your views.
The kits generally also have several custom views and layouts. You can refer to the following articles to learn more about them:
Источник
Getting Started With Android Studio
Android Studio is a fairly new IDE (Integrated Development Environment) made available for free by Google to Android developers. Android Studio is based on IntelliJ IDEA, an IDE that also offers a good Android development environment. In this tutorial, I’ll show you how to create a new Android project and take advantage of the features that Android Studio has to offer.
When you’re just getting started with Android Studio, it can be very helpful to use an Android app template. You can find over a thousand of them for sale on Envato Market:
Android app templates for sale on Envato Market
1. Project Setup
Before you start exploring Android Studio, you’ll first need to download and install it. Note that you need to have JDK 6 or higher installed. If you’re on Windows, launch the .exe file and follow the steps of the setup wizard. If you’re running OS X, mount the disk image by double-clicking it and drag Android Studio to your Applications folder.
If you’ve successfully completed the above steps, then your development environment should be set up correctly. You’re now ready to create your first Android application using Android Studio. When you launch Android Studio for the first time, you should be presented with a welcome screen, offering you a number of choices to get you started.
In this tutorial, we’re going to choose the New Project option. However, you can choose Import Project if you’d like to import a project from, for example, Eclipse, into Android Studio. Android Studio will convert the Eclipse project to an Android Studio project, adding the necessary configuration files for you.
If you select Open Project from the list of options, you can open projects created with either Android Studio or IntelliJ IDEA. By choosing Check out from Version Control, you can check out a copy of a project that’s under version control. This is a great way to quickly get up to speed with an existing project.
To get us started, choose New Project from the list of options. This will show you a list of options to configure your new project. In this tutorial, we’re going to create a simple application to show you some of Android Studio’s most important features. I’m sure you agree that there’s no better name for our project than HelloWorld.
As you can see in the above screenshot, I’ve named my application HelloWorld and set the module name to HelloWorld. If you’re unfamiliar with IntelliJ IDEA, you may be wondering what a module is. A module is a discrete unit of functionality that can be compiled, run, tested, and debugged independently. Modules contain source code, build scripts, and everything else required for their specific task.
When creating a new project, you can also set the package name of the project. By default, Android Studio sets the last element of the project’s package name to the name of the module, but you can change it to whatever you want.
The other settings are the project’s location on your machine, the minimum and target SDK, the SDK your project will be compiled with, and the project’s theme. You can also tell Android Studio to create an Activity class and a custom launch icon for you, and whether the project supports GridLayout, Fragments, a Navigation Drawer, or an Action Bar.
We won’t create a custom icon for this application so you can uncheck the checkbox labeled Create custom launch icon. Click Next to continue setting up your project.
Because we checked the checkbox Create activity in the previous step, you are asked to configure the Activity class Android Studio will create for you.
Since we’ll be starting with a blank Activity class, you can click Next to proceed to the next step in the setup process in which you’re asked to name the Activity class, the main layout, and the fragment layout. You can also set the navigation type, which we’ll leave at None for this project. Take a look at the next screenshot to see what your settings should look like.
After clicking Finish, you’ll be presented with Android Studio’s user interface with the project explorer on the left and the workspace on the right. With your project set up in Android Studio, it’s time to explore some of the key features of Android Studio.
2. Android Virtual Devices
An Android Virtual Device or AVD is an emulator configuration, allowing you to model an Android device. This makes running and testing applications on a wide range of devices much easier. With an Android Virtual Device, you can specify the hardware and software the Android Emulator needs to emulate.
The preferred way to create an Android Virtual Device is through the AVD Manager, which you can access in Android Studio by selecting Android > AVD Manager from the Tools menu.
If you’re development environment is set up correctly, the Android Virtual Device Manager should look similar to the screenshot below.
To create a new AVD, click New. on the right, give the AVD a name, and configure the virtual device as shown below. Click OK to create your first AVD.
To use your newly created AVD, select it from the list in the AVD manager, and click Start. on the right. If your AVD is set up correctly, the Android Emulator should launch as shown in the screenshot below.
With the Android Emulator up and running, it’s time to launch your application by selecting Run ‘helloworld’ from the Run menu. That’s how easy it is to run an application in the Android Emulator.
3. Live Layout
Android Studio’s live layout feature lets you preview your application’s user interface without the need to run it on a device or the emulator. The live layout feature is a powerful tool that will literally save you hours. Viewing your application’s user interface is much faster using live layouts.
To work with live layouts, double-click the XML layout file and select the Text tab at the bottom of the workspace. Select the Preview tab on the right of the workspace to preview the current layout. Any changes you make to the XML layout will be reflected in the preview on the right. Take a look at the screenshot below to get a better idea of this neat feature.
There are a number of other advantages of the live layout feature that are worth pointing out. You can, for example, create a variation of the XML layout you’re currently working on by selecting an option from the first menu in the Preview pane. You can, for example, create separate views for portrait and landscape and Android Studio will create the necessary folders and files for you.
The second menu in the Preview pane lets you change the size of the device shown in the Preview pane. The third menu lets you change the orientation of the device shown in the Preview pane, which makes it easy to see how a layout looks in different orientations and using different themes.
The fourth menu in the Preview pane gives you easy access to the Activity or fragment in which the layout is used. The Preview pane also lets you change the language used in the live layout to make it easy to preview a layout in different languages. The rightmost menu lets you change the API version.
The Preview pane also includes controls to zoom in on the layout, refresh the Preview pane, or take a screenshot.
4. Templates
Android Studio provides developers with a number of templates to speed up development. These templates automatically create an Activity and the necessary XML files. You can use these templates to create a basic Android application, which you can then run on a device or in the emulator.
With Android Studio, you can create a template when you create a new Activity . Right-click on the package name in the project navigator on the left, select New from the menu, and choose Activity from the list of options. Android Studio then shows you a list of templates, such as Blank Activity, Fullscreen Activity, and Tabbed Activity.
You can also select Image Asset from the menu, which will launch a wizard that guides you through the creation process. Let me show you how to create a new Activity based on the Login Activity template. Select the Login Activity option from the list of Activity templates to fire up the wizard.
As you can see in the above screenshot, I’ve named the Activity LoginActivity, set the Layout Name to activity_login, given the Activity a title of Sign In. The checkbox labeled Include Google+ sign in is checked by default. Uncheck it since we won’t be using this feature in our example.
You can optionally set the Hierarchical Parent of the new Activity . This will let you navigate back if you tap the device’s back button. We will leave this field empty. After clicking Finish, Android Studio creates the necessary files and folders for you. If all went well, you should see a new Activity and Layout in your project.
The next step is to set up the new Activity in the manifest file so it’s used as the main Activity when the application launches. As you can see in manifest file below, the LoginActivity class has its own activity node.
To make your application launch the LoginActivity you created, remove the activity node for the LoginActivity class and replace com.tuts.HelloWorld.MainActivity
with com.tuts.HelloWorld.LoginActivity . The result is that the application will now use the LoginActivity class as its main Activity .
When you build and run your application in the emulator, you should see a screen similar to the one shown below. This means that we’ve successfully replaced the blank Activity class with the newly created LoginActivity class.
5. Lint Tools
Testing your code is one thing, but it’s equally important to apply best practices when writing code. This will improve performance and the overall stability of your application. It’s also much easier to maintain a properly structured project.
Android Studio’s includes Android Lint, a static analyzer that analyzes your project’s source code. It can detect potential bugs and other problems in your code that are the compiler may overlook.
The below screenshot, for example, tells us that the LinearLayout in this layout is of no use. The nice thing about Android Lint is that it gives you a reason for the warning or error, which makes it easier to fix or resolve.
It’s good practice to run Android Studio’s lint tool from time to time to check your project for potential problems. The lint tool will even tell you if you have duplicate images or translations.
To run the lint tool, select Inspect Code… from the Analyze menu in Android Studio to start the process. When Android Studio has finished inspect your project, it will present you with the results at the bottom of the window. Note that in addition to Android Lint, Android Studio performs a number of other checks as well. Simply double-click an issue to navigate to the file in which the problem is located.
6. Rich Layout Editor
Android Studio has a rich layout editor in which you can drag and drop user interface components. You can also preview layouts on multiple screen configurations as we saw earlier in this tutorial.
The rich layout editor is very straightforward to use. We first need a layout to work with. Navigate to the layout folder in your project’s res folder, right-click the layout folder, and select New > Layout resource file from the menu that appears.
Give the new layout a name, set its root element, and click OK. Android Studio will automatically open the layout in the editor on the right.
At the bottom of the editor, you should see two tabs, Design and Text. Clicking the Text tab brings up the editor, allowing you to make changes to the currently selected layout.
Clicking the Design tab brings up another editor that shows you a preview of the layout. To add a widget to the layout, drag it from the list of widgets on the left to the layout on the right. It’s that simple.
Conclusion
In this tutorial, we’ve taken a brief look at some of the key features of Android Studio. It is very similar to IntelliJ IDEA, but it contains a number of important enhancements that make Android development easier, faster, and more enjoyable.
If you want to speed things up even more, try using an Android app template from Envato Market, or working with a freelance Android developer on Envato Studio.
Источник