Android Manual
Android Manual
If expression
fun main() {
val a = 2
val b = 3
var max = a
if (a < b) max = b
print(max)
Output:
3
// With else
fun main() {
val a = 2
val b = 3
var max = a
if (a > b) {
max = a
}
else {
max = b
}
Output:
3
// As expression
fun main() {
val a = 2
val b = 3
var max = a
Output:
3
println("max is $max")
println("maxOrLimit is $maxOrLimit")
}
Output:
max is 3
maxOrLimit is 3
Output: x == 2
Combine when Conditions
when (day) {
1, 2, 3, 4, 5 -> println("Weekday")
else -> println("Weekend")
}
}
Output:
Weekday
when (x) {
(y+z) -> print("y + z = x = $x")
else -> print("Condition is not satisfied")
}
}
Output:
y + z = x = 20
Kotlin when with block of code
when (day) {
1 -> {
println("First day of the week")
println("Monday")
}
2 -> {
println("Second day of the week")
println("Tuesday")
}
3 -> {
println("Third day of the week")
println("Wednesday")
}
4 -> println("Thursday")
5 -> println("Friday")
6 -> println("Saturday")
7 -> println("Sunday")
else -> println("Invalid day.")
}
}
Output:
Second day of the week
Tuesday
While loop
var i = 0
while (i < 5) {
println(i)
i++
}
Output:
0
1
2
3
4
Do while loop
var i = 0
do {
println(i)
i++
}
while (i < 5)
Output:
0
1
2
3
4
For Loop:
Output:
1
2
3
4
5
Example 2:
Output:
5
3
1
Example 3:
fun main() {
for (chars in 'a'..'g') {
println(chars)
}
}
Output:
a
b
c
d
e
f
g
Output:
Orange
Apple
Mango
Banana
Will iterate through the array using its index.
Output:
Orange
Apple
Mango
Banana
Break Statement
fun main(args: Array<String>) {
var i = 0;
while (i++ < 100) {
println(i)
if( i == 3 ){
break
}
}
}
Output:
1
2
3
Continue
var i = 0
while (i < 10) {
if (i == 4) {
i++
continue
}
println(i)
i++
}
Output:
0
1
2
3
5
6
7
8
9
Output:
i = 1 and j = 1
i = 1 and j = 2
i = 1 and j = 3
i = 2 and j = 1
Output:
i: 1, j: 1
i: 1, j: 2
i: 1, j: 3
i: 2, j: 1
Skipping i: 2, j: 2
i: 3, j: 1
i: 3, j: 2
i: 3, j: 3
B) Write a program to implement object-oriented concepts in Kotlin.
// Encapsulation: Using private variables with public getter and setter methods
class Person(private var name: String, private var age: Int) {
// Getter for name
fun getName(): String {
return name
}
// Display details
fun displayDetails() {
println("Name: $name, Age: $age")
}
}
// Derived class
class Dog : Animal() {
override fun sound() {
println("\nInheritance Concept")
println("The dog barks.")
}
}
// Polymorphism: Overloading
class Calculator {
fun add(a: Int, b: Int): Int {
return a + b
}
// Interface example
interface Vehicle {
fun start()
fun stop()
}
fun main() {
// Encapsulation example
println("Encapsulation concept")
val person = Person("John", 25)
person.displayDetails()
person.setName("Jane")
person.setAge(30)
println("Updated Details:")
person.displayDetails()
// Abstraction example
val circle = Circle(7.0)
println("\nAbstraction Concept")
circle.displayType()
println("Area of the circle: ${circle.area()}")
// Interface example
val car: Vehicle = Car()
println("\nInterface Concept")
car.start()
car.stop()
}
Output:
Encapsulation concept
Name: John, Age: 25
Updated Details:
Name: Jane, Age: 30
Inheritance Concept
The dog barks.
Polymorphism Concept
Sum of 2 numbers: 15
Sum of 3 numbers: 30
Abstraction Concept
This is a shape.
Area of the circle: 153.93804002589985
Interface Concept
Car is starting.
Car is stopping.
Practical 2
Write an android application demonstrating response to event/user
interaction for
a. Checkbox
b. Radio button
c. Button
d. Spinner
Note: If the loading bar is displayed, please do not take any action and
wait patiently.
Step 2: Setting Up the Environment
1.1 MainActivity.kt
After the loading process, Android Studio will open the MainActivity.kt file.
You'll notice some prewritten code in the file, which we won't be using.
Step 3: activity_main.xml
1.1 Open the activity_main.xml file. By default, it should look like this.
2.2 Remove the existing 'Hello World!' text and start adding the desired
components from the Palette window.
• Add 2-3 checkboxes, 2 radio buttons, a spinner, and a submit button.
• Include TextViews between them for better organization.
Note: Since we are working with ConstraintLayout, each component
must be anchored to at least two points.
Otherwise, it will default to the top-left corner.
Constraint handles
First, add a TextView, resize it, and adjust its constraint handles.
Now, add a checkbox by dragging it from Palette > Buttons. Resize it to make
it slightly wider, ensuring it can accommodate longer words.
After adding and positioning the first checkbox, drag the baseline handle of the
TextView to the Upper handle of the checkbox. Then, connect the side handles
of the checkbox to the edges of the layout.
Add two more checkboxes, resize them, and connect the baseline handle of
the upper checkbox to the one below it.
Repeat this process to add the remaining components, including the radio
buttons, spinner, and submit button.
OR
If it's too complicated or not running properly on your computer, try this
instead:
In activity_main.xml, open the code editor window by clicking the three lines
icon, or use the shortcut Alt + Shift + Right Arrow.
<CheckBox android:id="@+id/checkbox_java"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Java" />
<CheckBox android:id="@+id/checkbox_kotlin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kotlin" />
<CheckBox android:id="@+id/checkbox_python"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Python" />
<CheckBox android:id="@+id/checkbox_javascript"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="JavaScript" />
<RadioGroup android:id="@+id/radioGroup_interest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton android:id="@+id/radioYes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes" />
<RadioButton android:id="@+id/radioNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No" />
</RadioGroup>
<Spinner android:id="@+id/spinnerMode"
android:layout_width="match_parent"
android:layout_height="42dp" />
</LinearLayout>
We're done with the activity_main.xml file. If you're using the first method,
i.e., ConstraintLayout, update the attributes such as id and text to match the
code provided above.
Step 4: activity_summary.xml
Since we will summarize our selections on the next page, let's create it now.
Go to the Resource Manager (shapes icon on the left side).
<TextView android:id="@+id/text_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Summary"
android:textSize="22sp"
android:textStyle="bold" />
<TextView android:id="@+id/text_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_marginTop="16dp" />
<Button
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back to Form"
android:layout_marginTop="16dp" />
</LinearLayout>
Step 5: MainActivity.kt
Navigate to the MainActivity.kt file and paste the following code into it.
import android.os.Bundle
import android.widget.Spinner
import android.widget.Button
import android.widget.RadioGroup
import android.widget.CheckBox
import android.widget.ArrayAdapter
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
intent.putExtra("languages", selectedLanguages)
intent.putExtra("interestedInCourse", interestedInCourse)
intent.putExtra("modeOfAttending", modeOfAttending)
startActivity(intent)
}
}
// Function to get selected programming languages
private fun getSelectedLanguages(): String {
val languages = mutableListOf<String>()
if (checkBoxJava.isChecked) languages.add("Java")
if (checkBoxKotlin.isChecked) languages.add("Kotlin")
if (checkBoxPython.isChecked) languages.add("Python")
if (checkBoxJavaScript.isChecked)
languages.add("JavaScript")
return languages.joinToString(", ")
}
// Function to get if the user is interested in applying
Note: Make sure to add this line at the top of your code and replace
project_name with the name you provided when creating the project (in
my case, manual_xyz).
package come.example.project_name
Step 6: SecondaryActivity.kt
Let's create a .kt file for the second page.
Go to the Project tab (on the sidebar or use the shortcut ALT + 1), then
navigate to the location of the MainActivity.kt file:
app -> kotlin + Java -> com.example.project_name
Now, click once on the MainActivity.kt file, right-click to open the context
menu, select New, and then choose Kotlin Class/File.
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.TextView
import android.widget.Button
textDetails.text = summary
finish() // Finishes this activity and goes back to the previous one
}
}
}
Step 7: Final Tweaks
We need to declare our SecondaryActivity in the AndroidManifest.xml file.
In the Project tab, navigate to the AndroidManifest.xml file
app -> manifests -> AndroidManifest.xml
Click the play button at the top or use the shortcut 'SHIFT + F10'.
wait patiently
Done
Possible errors:
1. Cross-check all names to ensure consistency throughout the
application.
2. If an SDK error occurs, click the link and refactor accordingly.
PRACTICAL 3
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/androi
d" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.viewpager.widget.ViewPager
android:id="@+id/idViewPager"
android:layout_width="343dp"
android:layout_height="272dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
STEP 2:- Create a layout file for ImageView in View Pager
Navigate to the app > res > layout > Right-click on it > New > Layout
Resource file and specify the name as image_slider_item. Paste the
following code to the image_slider_item file. Comments are added in the
code to understand the code in detail.
Code:-
package com.example.practical_no_4
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import
android.widget.RelativeLayout
import androidx.viewpager.widget.PagerAdapter
import java.util.*
class ViewPagerAdapter(val context: Context, val imageList: List<Int>)
: PagerAdapter() { // on below line we are creating a method
// as get count to return the size of the list.
override fun getCount(): Int {
return imageList.size
}
// on below line we are returning the object
override fun isViewFromObject(view: View, `object`: Any): Boolean {
return view === `object` as RelativeLayout
}
// on below line we are initializing
// our item and inflating our layout file
override fun instantiateItem(container: ViewGroup, position: Int): Any
{
// on below line we are initializing
// our layout inflater. val
mLayoutInflater =
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
// on below line we are inflating our custom
// layout file which we have created.
val itemView: View =
mLayoutInflater.inflate(R.layout.image_slider_item, container, false)
// on below line we are initializing
// our image view with the id. val imageView: ImageView =
itemView.findViewById<View>(R.id.idIVImage) as ImageView
// on below line we are setting
// image resource for image view.
imageView.setImageResource(imageList.get(position))
// on the below line we are adding this
// item view to the container.
Objects.requireNonNull(container).addView(itemView)
// on below line we are simply
// returning our item view. return itemView
}
// on below line we are creating a destroy item method. override fun
destroyItem(container: ViewGroup, position: Int,
`object`: Any) { // on below line we are removing view
container.removeView(`object` as RelativeLayout)
}
}
import android.os.Bundle
import
androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
class MainActivity : AppCompatActivity() {
// on below line we are creating variable for view pager,
// viewpager adapter and the image list.
lateinit var viewPager: ViewPager
lateinit var viewPagerAdapter:
ViewPagerAdapter lateinit var imageList:
List<Int>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// initializing variables
// of below line with their id.
viewPager = findViewById(R.id.idViewPager)
// on below line we are initializing
// our image list and adding data to it. imageList
= ArrayList<Int>()
imageList = imageList + R.drawable.nature1 //your image
name imageList = imageList + R.drawable.nature2 //your
image name imageList = imageList + R.drawable.nature3
//your image name imageList = imageList +
R.drawable.nature4 //your image name imageList =
imageList + R.drawable.nature5 //your image name
// on below line we are initializing our view
// pager adapter and adding image list to it.
viewPagerAdapter = ViewPagerAdapter(this@MainActivity,
imageList)
// on below line we are setting
// adapter to our view pager.
viewPager.adapter = viewPagerAdapter
}
}
STEP 1:-In this step first we will create a new Android project in Android
studio.
STEP2:-Working with the activity_main.xml file.
Now let us design the UI of the activity_main file. In this file, we need to first
design two buttons each for explicit intent and implicit intent.
Navigate to app > res > layout > activity_main.xml and paste the following
code to activity_main.xml file.
Code:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/bt_explicit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_gravity="center_horizontal"
android:text="EXPLICIT INTENT"
android:onClick="callSecondActivity" />
<Button
android:id="@+id/bt_implicit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:text="IMPLICIT INTENT" />
</LinearLayout>
STEP 3:- Working with the MainActivity.kt file.
In the MainActivity.kt file paste the following code.
package com.example.practical_5
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import android.net.Uri
bt_explicit = findViewById<Button>(R.id.bt_explicit)
bt_implicit = findViewById<Button>(R.id.bt_implicit)
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:text="Explicit Intent "
android:textSize="20sp"/>
<Button
android:id="@+id/bt_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Call First Activity"
android:onClick="callFirstActivity"
android:layout_gravity="center"
android:layout_marginTop="10dp"/>
</LinearLayout>
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class Explicit_intent : AppCompatActivity() {
var bt_back: Button? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activiy_explicit_intent)
bt_back = findViewById<Button>(R.id.bt_back)
}
fun callFirstActivity(view: View?) {
val i = Intent(this, MainActivity::class.java)
startActivity(i)
Toast.makeText(this, "We are moved to First Activity",
Toast.LENGTH_SHORT)
.show()
}
}
Output:
Practical 5
Before proceeding with the steps, please read the following points:
1. This guide does not cover everything from scratch.
2. It assumes you have some familiarity with Android Studio's UI.
3. Avoid blindly copying and pasting—ensure your project name and
required libraries are correctly set.
4. This manual covers only a basic structure—nothing complex or fancy.
5. Experiment with UI elements, attributes, and other settings to enhance
your understanding.
6. If you encounter any errors, try debugging them yourself first.
7. If an Android SDK error occurs, simply click on the link and refactor it
accordingly.
Step 1: Project Setup
Step 2: MainActivity.kt
2.1: Opening MainActivity.kt
By default, your project should open with MainActivity.kt.
If not, navigate to app > java + kotlin > com.example.ProjectName >
MainActivity.kt and open the file.
Note: This line should remain unchanged, reflecting your project's package
name.
Now, copy and paste the following code directly below the package name
line.
Code:
import android.os.Bundle
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
// Fetch the stored data in onResume() Because this is what will be called
when the app opens again
override fun onResume() {
super.onResume()
// Fetching the stored data from the SharedPreference
val sh = getSharedPreferences("MySharedPref", MODE_PRIVATE)
val s1 = sh.getString("name", "")
val a = sh.getInt("age", 0)
// When the user closes the application onPause() will be called and data will
be stored
override fun onPause() {
super.onPause()
// Creating a shared pref object with a file name "MySharedPref" in
private mode
val sharedPreferences = getSharedPreferences("MySharedPref",
MODE_PRIVATE)
val myEdit = sharedPreferences.edit()
// write all the data entered by the user in SharedPreference and apply
myEdit.putString("name", name.text.toString())
myEdit.putInt("age", age.text.toString().toInt())
myEdit.apply()
}
}
Note: Since we haven't created any UI elements in the XML file yet, you
may see two errors for edit1 and edit2 IDs. You can ignore them for now.
Step 3: activity_main.xml
3.1: Opening activity_main.xml file to code
navigate to app > res > layout > activity_main.xml and open the file.
By default, it should look like this.
open the code editor window by clicking the three lines icon, or use the
shortcut Alt + Shift + Right Arrow.
Code:
<?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"
tools:context=".MainActivity"
tools:ignore="HardcodedText">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="Shared Preferences Demo"
android:textColor="@android:color/black"
android:textSize="24sp" />
<!--EditText to take the data from the user and save the data in
SharedPreferences-->
<EditText
android:id="@+id/edit1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="Enter your Name"
android:padding="10dp" />
<!--EditText to take the data from the user and save the data in
SharedPreferences-->
<EditText
android:id="@+id/edit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edit1"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="Enter your Age"
android:inputType="number"
android:padding="10dp" />
</RelativeLayout>
Note: Wait patiently while Android Studio builds the app in the virtual
machine. If an SDK error occurs, click the provided link, refactor
accordingly, and then re-run the application.
DONE
Once completed, enter some text and age in the input fields (EditText),
then close the application—even remove it from the background. When
you reopen the app, you'll see that your last input has been saved.
Practical 6
MainActivity.kt
package com.example.canva
import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color import
android.graphics.Paint import
android.os.Build
import androidx.appcompat.app.AppCompatActivity import
android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.widget.ImageView
import androidx.annotation.RequiresApi
@RequiresApi(Build.VERSION_CODES.R)
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Initializing the ImageView
mImageView = findViewById(R.id.image_view_1)
// Getting the current window dimensions
val currentDisplay = windowManager.currentWindowMetrics
val dw = currentDisplay.bounds.width()
val dh = currentDisplay.bounds.height()
MotionEvent.ACTION_MOVE -> {
upX = event.x
upY = event.y
canvas.drawLine(downX, downY, upX, upY, paint)
downX = upX // Update start point for continuous drawing
downY = upY
mImageView.invalidate()
}
MotionEvent.ACTION_UP -> {
upX = event.x
upY = event.y
canvas.drawLine(downX, downY, upX, upY, paint)
mImageView.invalidate()
}
}
return true // Ensure event is consumed
}
activity_main.xml
<ImageView
android:id="@+id/image_view_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:ignore="ContentDescription" />
</RelativeLayout>
Output:
Practical 7
Create an Android application to use a camera and capture image/video and
display them on the screen.
activity_main.xml file
Mainactivity.kt file
package com.example.practical_7
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import android.provider.MediaStore
import android.view.View
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
companion object {
// Define the pic id
private const val pic_id = 123
}
}
Output:
Practical 8
Step 1: Create a new directory (Android Resource Directory) in the res directory.
MainActivity.kt
package com.example.menus
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.ContextMenu
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.Toolbar
//Find TextView
val atextView: TextView = findViewById(R.id.textViews)
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/material_dynamic_primary70"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light"
android:gravity="center"
android:padding="16dp"
android:text="Long Press Me for Context Menu"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.33" />
<TextView
android:id="@+id/textViews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light"
android:gravity="center"
android:padding="16dp" android:text="Tap
Me for Pop-up Menu"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.642" />
</androidx.constraintlayout.widget.ConstraintLayout>
context_menu.xml
menu.xml
<item
android:id="@+id/overflowMenu"
android:icon="@drawable/ic_3_dots"
android:title="Options"
app:showAsAction="always">
<menu>
<item
android:id="@+id/settings"
android:icon="@drawable/ic_settings"
android:title="SETTINGS"
app:showAsAction="never" />
<item
android:id="@+id/about"
android:icon="@drawable/ic_about"
android:title="ABOUT"
app:showAsAction="never" />
<item
android:id="@+id/exit"
android:icon="@drawable/ic_exit"
android:title="EXIT"
app:showAsAction="never" />
</menu>
</item>
</menu>
Output:
Note: The “@drawable/ic_3_dots”, “@drawable/ic_settings”,
“@drawable/ic_about”, “@drawable/ic_exit” are vectors used for Options menu.
Follow the steps below to define vectors in your project: