Introduction
Android is one of the most popular operating systems for mobile. Nowadays, gestures are an important element of Android apps. Gestures make it easy to access the apps and makes things convenient for the user.
In this article, I will show you how to implement gestures in Android applications using Android Studio. Android is a kernel based operating system. In Android, users can modify the GUI components and source code.
Requirements
- Android Studio
- A little knowledge of XML and JAVA
- Android Emulator (or) Android mobile
Steps to be followed
Carefully follow my steps to implement gestures in Android applications using Android Studio. I have included the source code too.
Step 1
Open Android Studio and start a new project.
![Android]()
Step 2
Put the application name and company domain. If you wish to use C++ for coding this project, mark the "Include C++ support" checkbox and click Next.
![Android]()
Step 3
Select the Android minimum SDK and click Next.
![Android]()
Step 4
Choose "Basic Activity" and click Next.
![Android]()
Step 5
Put the activity name and layout name. Android Studio basically takes Java class nameas what you provide for activity name. Now, click Finish.
![Android]()
Step 6
Go to activity_main.xml and click the text botton. This xml file contains the designing code for Android app. In the activity_main.xml file, copy and paste the below code.
Activity_main.xml code
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout 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"
- tools:context="ganeshannt.gesturesample.MainActivity">
-
-
- <TextView
- android:id="@+id/ganimsg"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="230dp"
- android:text="TextView"
- android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
- </RelativeLayout>
User interface
![Android]()
Step 7
In the MainActivity.java file, copy and paste the below code. Java is back-end language for Android. Do not replace your package name otherwise the app will not run.
MainActivity.java code
Step 8
As we need to perform each java activity change in AndroidManifest, add the below code in AndroidManifest.xml file.
AndroidManifest.xml code
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="ganeshannt.gesturesample">
-
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-
- </manifest>
Step 9This is our user interface of the application. Click the "Make Project" option.
![Android]()
Step 10
Run the application >> select virtual machine >> click OK.
![Android]()
Deliverables
Here, we have successfully implemented gestures in an Android application.
![Android]()
![Android]()
![Android]()
![Android]()
Don’t forgot to like and follow me. If you have any doubts, just comment below.
Source code - https://github.com/GaneshanNT/GestureSample