SlideShare a Scribd company logo
Learn Xamarin Absolute Beginners
Permissions, Building the App GUI Menus
Eng Teong Cheah
Microsoft MVP in Visual Studio &
Development Technologies
Agenda
•Permissions
•Building the App GUI
•Menus
Permission
Permissions
In Android, by default, no application has permissions to perform any
operations that would have an effect on the user or the operating
system. In order for an App to perform a task, it must declare the
permissions. The App cannot perform the task until the permission
are granted by the Android system. This mechanism of permissions
stops applications from doing as they wish without the user’s
constent.
Permissions
Permissions are to be
recorded in
AndroidManifest.xml file. To
add permissions, we double-
click on properties, then go
to Android Manifest Required
permissions will appear.
Check the appropriate
permissions you wish to add.
Permissions
Camera – It provides permission to access the device’s camera.
Internet – It provides access to network resources.
ReadContacts – It provides access to read the contacts on your
device.
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Permissions
ReadExtrnalStorage – It provides access to read and store data on an
external storage.
Calendar – It allows an app access to the calendar on the user device
and events. This permission can be dangerous, as it grants an app
the ability to send emails to guests without the owner’s awareness.
The syntax for adding this permission is as shown below:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission-group.CALENADAR" />
Permissions
SMS – An app with this permission has the ability to use the devices
messaging services. It includes reading, writing, and editing SMS and
MMS messages. Its syntax is as shown below.
Location – An app with this permission can access the device’s
location using the GPS network.
<uses-permission android:name="android.permission-group.SMS" />
<uses-permission android:name="android.permission-group.LOCATION" />
Permissions
Bluetooth – An app this permission can exchange data files with
other Bluetooth enabled devices wirelessly.
<uses-permission android:name="android.permission.BLUETOOTH" />
Building the App GUI
Building the App GUI
When a new Android project is
created, there are some files that are
added to the project, by default. We
call these default project files and
folders as Android Resources. Take a
look at the following screenshot.
Android Resources
The default Android resources include the following -
AndroidManifest.xml file – It contains information about your Android
applications, e.g. the application name, permissions, etc.
Resources folder - Resources can be images, layouts, strings, etc.
that can be loaded via Android’s resource system.
Android Resources
Resources / drawable folder – It stores all the images that you are
going to use in your application.
Resources / layout folder -It contains all the Android XML file (.axml)
that Android uses to build user interfaces.
The Resources / value folder - It contains XML files to declare key-
value pairs for strings (and other types) throughout an application.
This is how localization for multiple languages is normally set up on
Android.
Android Resources
Resources.designer.cs – This file is created automatically when the
Android projected is created and it conatins unique identifiers that
reference the Android resources.
MainActivity.cs file - This is the first activity of your Android
application and from where the main application actions are
launched from.
Android Resources
Resource files can be accessed programmatically through a unique ID
which is stored in the resources.designer.cs file. The ID is contained
user a class call Resource. Any resource added to the project is
automatically generated inside the resource class.
Demo
Menus
Popup Menus
Menus
Popup Menus
A popup menu refers to a menu that is attached to a view; it is also
referred to as a shortcut menu. Let’s see how to add a popup menu
to an Android App.
Create a new project and call popUpMenu App. Open Main.axml and
create a button which will be used to display the popup menu.
Menus
Popup Menus
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:background = "#d3d3d3"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent">
<Button
android:id = "@+id/popupButton"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:text = "Show popup menu"
android:background = "@android:color/holo_green_dark"
android:textColor = "@android:color/black" />
</LinearLayout>
Menus
Popup Menus
Create a new folder under the Resources folder and call it Menu.
Inside the Menu folder, add a new xml file called popMenu.xml.
Under popMenu.xml, add the following menu items.
Menus
<?xml version = "1.0" encoding="utf-8"?>
<menu xmlns:android = "http://schemas.android.com/apk/res/android">
<item
android:id = "@+id/file_settings"
android:icon = "@drawable/img_settings"
android:title = "Settings"
android:showAsAction = "ifRoom">
<item
android:id = "@+id/new_game1"
android:icon = "@drawable/imgNew"
android:title = "New File Settings"/>
<item
android:id = "@+id/help"
android:icon = "@drawable/img_help"
android:title = "Help" />
<item
android:id = "@+id/about_app"
android:icon = "@drawable/img_help"
android:title = "About app"/>
</item>
</menu>
Menus
Popup Menus
After adding the menu items, go to mainActivity.cs to display the
popup menu on button click.
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button showPopupMenu = FindViewById<Button>(Resource.Id.popupButton);
showPopupMenu.Click += (s, arg) => {
PopupMenu menu = new PopupMenu(this, showPopupMenu);
menu.Inflate(Resource.Menu.popMenu);
menu.Show();
};
}
Demo
Option Menus
Menus
Option Menus
Options Menu is a collection of menus that are primary to an App
and are mainly used to store settings, search, etc. Here, we are going
to create a menu for settings with three items inside, i.e., New File
Settings, Help, and About App.
To create an options menu, we must create a new XML layout file in
the resources folder. First of all, we will add a new XML file. Right-click
on the Layout folder, then go to Add-> New item -> Visual C# ->
XML file.
Menus
Option Menus
Choose an appropriate name for the layout file. In our example, we
will call our file myMenu.xml.
Inside myMenu.xml, we are going to create a new menu and add
items inside. The following code shows how to do it.
Menus
<?xml version = "1.0" encoding = "utf-8"?>
<menu xmlns:android = "http://schemas.android.com/apk/res/android">
<item
android:id = "@+id/file_settings"
android:icon = "@drawable/img_settings"
android:title = "Settings"
android:showAsAction = "ifRoom">
<menu>
<item
android:id = "@+id/new_game1"
android:icon = "@drawable/imgNew"
android:title = "New File Settings" />
<item
android:id = "@+id/help"
android:icon = "@drawable/img_help"
android:title = "Help" />
<item
android:id = "@+id/about_app"
android:icon = "@drawable/img_help"
android:title = "About app"/>
</menu>
</item>
</menu>
Menus
Option Menus
Next, we navigate to MainActivity.cs and create an override class for
onOptionsMenu().
public override bool OnCreateOptionsMenu(IMenu menu) {
MenuInflater.Inflate(Resource.Menu.myMenu, menu);
return base.OnPrepareOptionsMenu(menu);
}
Menus
Option Menus
Next, we create an action to respond to the settings menu when it is
selected. To do this, we create another override class for the
OnOptionsItemSelected() menu.
public override bool OnOptionsItemSelected(IMenuItem item) {
if (item.ItemId == Resource.Id.file_settings) {
// do something here...
return true;
}
return base.OnOptionsItemSelected(item);
}
Menus
Option Menus
Our final complete code will looks as follows-
namespace optionsMenuApp {
[Activity(Label = "options Menu", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity {
public override bool OnCreateOptionsMenu(IMenu menu) {
MenuInflater.Inflate(Resource.Menu.myMenu, menu);
return base.OnPrepareOptionsMenu(menu);
}
public override bool OnOptionsItemSelected(IMenuItem item) {
if (item.ItemId == Resource.Id.file_settings) {
// do something here...
return true;
}
return base.OnOptionsItemSelected(item);
}
}
}
Demo
Related Content
•TutorialsPoint
www.tutorialspoint.com
Thank You

More Related Content

PPTX
Lesson 10
PPT
Day 4: Android: UI Widgets
PDF
01 08 - graphical user interface - layouts
PDF
01 09 - graphical user interface - basic widgets
PPT
android layouts
PPT
Multiple Activity and Navigation Primer
PPTX
Android Programming.pptx
PPTX
Lesson 10
Day 4: Android: UI Widgets
01 08 - graphical user interface - layouts
01 09 - graphical user interface - basic widgets
android layouts
Multiple Activity and Navigation Primer
Android Programming.pptx

What's hot (20)

PPTX
Android App Development (Basics)
PDF
Ch2 first app
PPT
View groups containers
PPTX
IntelliJ IDEA Plugin Development
PPTX
Android Layout.pptx
PDF
Android ui layout
PPTX
Create an android app for database creation using.pptx
PPTX
Simple Android Project (SAP)... A Test Application
PPTX
Android Life Cycle
PDF
Chapter 10 - Views Part 2
PDF
Android layouts
PDF
Android Screen Containers & Layouts
PPTX
Android development session 3 - layout
PDF
Chapter 5 - Layouts
PPTX
Day 15: Working in Background
PDF
Android session 2
PDF
Android session 3
PPTX
Introduction to android
PPSX
10 asp.net session14
PPT
Android Basics
Android App Development (Basics)
Ch2 first app
View groups containers
IntelliJ IDEA Plugin Development
Android Layout.pptx
Android ui layout
Create an android app for database creation using.pptx
Simple Android Project (SAP)... A Test Application
Android Life Cycle
Chapter 10 - Views Part 2
Android layouts
Android Screen Containers & Layouts
Android development session 3 - layout
Chapter 5 - Layouts
Day 15: Working in Background
Android session 2
Android session 3
Introduction to android
10 asp.net session14
Android Basics
Ad

Similar to Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus (20)

PDF
Basics and different xml files used in android
PDF
Ap quiz app
PDF
Learn Xamarin Absolute Beginners - Application Manifest, Android Resources & ...
PPT
Beginning Native Android Apps
PPTX
Android Development Basics
DOCX
Creation of simple application using - step by step
PPTX
Mobile Application Development-Components and Layouts
PPT
Android Bootcamp Tanzania:understanding ui in_android
PPTX
Android Tutorials : Basic widgets
PDF
Android app development guide for freshers by ace web academy
PPTX
Chapter 2 lesson-1 adding the action bar
PPT
Android lifecycle
DOCX
Android menus in android-chapter15
PPTX
I/O Rewind 215: What's new in Android
KEY
Android Workshop
PPTX
mobile application development -unit-3-
DOCX
4.preference management
PPT
Lec005 android start_program
PPT
Android Button
PPTX
Android Development : (Android Studio, PHP, XML, MySQL)
Basics and different xml files used in android
Ap quiz app
Learn Xamarin Absolute Beginners - Application Manifest, Android Resources & ...
Beginning Native Android Apps
Android Development Basics
Creation of simple application using - step by step
Mobile Application Development-Components and Layouts
Android Bootcamp Tanzania:understanding ui in_android
Android Tutorials : Basic widgets
Android app development guide for freshers by ace web academy
Chapter 2 lesson-1 adding the action bar
Android lifecycle
Android menus in android-chapter15
I/O Rewind 215: What's new in Android
Android Workshop
mobile application development -unit-3-
4.preference management
Lec005 android start_program
Android Button
Android Development : (Android Studio, PHP, XML, MySQL)
Ad

More from Eng Teong Cheah (20)

PDF
Modern Cross-Platform Apps with .NET MAUI
PDF
Efficiently Removing Duplicates from a Sorted Array
PDF
Monitoring Models
PDF
Responsible Machine Learning
PDF
Training Optimal Models
PDF
Deploying Models
PDF
Machine Learning Workflows
PDF
Working with Compute
PDF
Working with Data
PDF
Experiments & TrainingModels
PDF
Automated Machine Learning
PDF
Getting Started with Azure Machine Learning
PDF
Hacking Containers - Container Storage
PDF
Hacking Containers - Looking at Cgroups
PDF
Hacking Containers - Linux Containers
PDF
Data Security - Storage Security
PDF
Application Security- App security
PDF
Application Security - Key Vault
PDF
Compute Security - Container Security
PDF
Compute Security - Host Security
Modern Cross-Platform Apps with .NET MAUI
Efficiently Removing Duplicates from a Sorted Array
Monitoring Models
Responsible Machine Learning
Training Optimal Models
Deploying Models
Machine Learning Workflows
Working with Compute
Working with Data
Experiments & TrainingModels
Automated Machine Learning
Getting Started with Azure Machine Learning
Hacking Containers - Container Storage
Hacking Containers - Looking at Cgroups
Hacking Containers - Linux Containers
Data Security - Storage Security
Application Security- App security
Application Security - Key Vault
Compute Security - Container Security
Compute Security - Host Security

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Review of recent advances in non-invasive hemoglobin estimation
sap open course for s4hana steps from ECC to s4
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine Learning_overview_presentation.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus

  • 1. Learn Xamarin Absolute Beginners Permissions, Building the App GUI Menus Eng Teong Cheah Microsoft MVP in Visual Studio & Development Technologies
  • 4. Permissions In Android, by default, no application has permissions to perform any operations that would have an effect on the user or the operating system. In order for an App to perform a task, it must declare the permissions. The App cannot perform the task until the permission are granted by the Android system. This mechanism of permissions stops applications from doing as they wish without the user’s constent.
  • 5. Permissions Permissions are to be recorded in AndroidManifest.xml file. To add permissions, we double- click on properties, then go to Android Manifest Required permissions will appear. Check the appropriate permissions you wish to add.
  • 6. Permissions Camera – It provides permission to access the device’s camera. Internet – It provides access to network resources. ReadContacts – It provides access to read the contacts on your device. <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
  • 7. Permissions ReadExtrnalStorage – It provides access to read and store data on an external storage. Calendar – It allows an app access to the calendar on the user device and events. This permission can be dangerous, as it grants an app the ability to send emails to guests without the owner’s awareness. The syntax for adding this permission is as shown below: <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission-group.CALENADAR" />
  • 8. Permissions SMS – An app with this permission has the ability to use the devices messaging services. It includes reading, writing, and editing SMS and MMS messages. Its syntax is as shown below. Location – An app with this permission can access the device’s location using the GPS network. <uses-permission android:name="android.permission-group.SMS" /> <uses-permission android:name="android.permission-group.LOCATION" />
  • 9. Permissions Bluetooth – An app this permission can exchange data files with other Bluetooth enabled devices wirelessly. <uses-permission android:name="android.permission.BLUETOOTH" />
  • 11. Building the App GUI When a new Android project is created, there are some files that are added to the project, by default. We call these default project files and folders as Android Resources. Take a look at the following screenshot.
  • 12. Android Resources The default Android resources include the following - AndroidManifest.xml file – It contains information about your Android applications, e.g. the application name, permissions, etc. Resources folder - Resources can be images, layouts, strings, etc. that can be loaded via Android’s resource system.
  • 13. Android Resources Resources / drawable folder – It stores all the images that you are going to use in your application. Resources / layout folder -It contains all the Android XML file (.axml) that Android uses to build user interfaces. The Resources / value folder - It contains XML files to declare key- value pairs for strings (and other types) throughout an application. This is how localization for multiple languages is normally set up on Android.
  • 14. Android Resources Resources.designer.cs – This file is created automatically when the Android projected is created and it conatins unique identifiers that reference the Android resources. MainActivity.cs file - This is the first activity of your Android application and from where the main application actions are launched from.
  • 15. Android Resources Resource files can be accessed programmatically through a unique ID which is stored in the resources.designer.cs file. The ID is contained user a class call Resource. Any resource added to the project is automatically generated inside the resource class.
  • 16. Demo
  • 17. Menus
  • 19. Menus Popup Menus A popup menu refers to a menu that is attached to a view; it is also referred to as a shortcut menu. Let’s see how to add a popup menu to an Android App. Create a new project and call popUpMenu App. Open Main.axml and create a button which will be used to display the popup menu.
  • 20. Menus Popup Menus <?xml version = "1.0" encoding = "utf-8"?> <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:background = "#d3d3d3" android:layout_width = "fill_parent" android:layout_height = "fill_parent"> <Button android:id = "@+id/popupButton" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Show popup menu" android:background = "@android:color/holo_green_dark" android:textColor = "@android:color/black" /> </LinearLayout>
  • 21. Menus Popup Menus Create a new folder under the Resources folder and call it Menu. Inside the Menu folder, add a new xml file called popMenu.xml. Under popMenu.xml, add the following menu items.
  • 22. Menus <?xml version = "1.0" encoding="utf-8"?> <menu xmlns:android = "http://schemas.android.com/apk/res/android"> <item android:id = "@+id/file_settings" android:icon = "@drawable/img_settings" android:title = "Settings" android:showAsAction = "ifRoom"> <item android:id = "@+id/new_game1" android:icon = "@drawable/imgNew" android:title = "New File Settings"/> <item android:id = "@+id/help" android:icon = "@drawable/img_help" android:title = "Help" /> <item android:id = "@+id/about_app" android:icon = "@drawable/img_help" android:title = "About app"/> </item> </menu>
  • 23. Menus Popup Menus After adding the menu items, go to mainActivity.cs to display the popup menu on button click. protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); Button showPopupMenu = FindViewById<Button>(Resource.Id.popupButton); showPopupMenu.Click += (s, arg) => { PopupMenu menu = new PopupMenu(this, showPopupMenu); menu.Inflate(Resource.Menu.popMenu); menu.Show(); }; }
  • 24. Demo
  • 26. Menus Option Menus Options Menu is a collection of menus that are primary to an App and are mainly used to store settings, search, etc. Here, we are going to create a menu for settings with three items inside, i.e., New File Settings, Help, and About App. To create an options menu, we must create a new XML layout file in the resources folder. First of all, we will add a new XML file. Right-click on the Layout folder, then go to Add-> New item -> Visual C# -> XML file.
  • 27. Menus Option Menus Choose an appropriate name for the layout file. In our example, we will call our file myMenu.xml. Inside myMenu.xml, we are going to create a new menu and add items inside. The following code shows how to do it.
  • 28. Menus <?xml version = "1.0" encoding = "utf-8"?> <menu xmlns:android = "http://schemas.android.com/apk/res/android"> <item android:id = "@+id/file_settings" android:icon = "@drawable/img_settings" android:title = "Settings" android:showAsAction = "ifRoom"> <menu> <item android:id = "@+id/new_game1" android:icon = "@drawable/imgNew" android:title = "New File Settings" /> <item android:id = "@+id/help" android:icon = "@drawable/img_help" android:title = "Help" /> <item android:id = "@+id/about_app" android:icon = "@drawable/img_help" android:title = "About app"/> </menu> </item> </menu>
  • 29. Menus Option Menus Next, we navigate to MainActivity.cs and create an override class for onOptionsMenu(). public override bool OnCreateOptionsMenu(IMenu menu) { MenuInflater.Inflate(Resource.Menu.myMenu, menu); return base.OnPrepareOptionsMenu(menu); }
  • 30. Menus Option Menus Next, we create an action to respond to the settings menu when it is selected. To do this, we create another override class for the OnOptionsItemSelected() menu. public override bool OnOptionsItemSelected(IMenuItem item) { if (item.ItemId == Resource.Id.file_settings) { // do something here... return true; } return base.OnOptionsItemSelected(item); }
  • 31. Menus Option Menus Our final complete code will looks as follows- namespace optionsMenuApp { [Activity(Label = "options Menu", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { public override bool OnCreateOptionsMenu(IMenu menu) { MenuInflater.Inflate(Resource.Menu.myMenu, menu); return base.OnPrepareOptionsMenu(menu); } public override bool OnOptionsItemSelected(IMenuItem item) { if (item.ItemId == Resource.Id.file_settings) { // do something here... return true; } return base.OnOptionsItemSelected(item); } } }
  • 32. Demo