Android generates user interfaces either from XML or from Java code.
Views
Creating and adding a new View to a Layout in XML
![UI Views](images/UIviews.jpg)
View Groups
A ViewGroupis a special view that can contain other views.
List view
![UI List View](images/UIlistview.jpg)
Layouts
A Layout is a type of GroupView. It holds views in a certain layout on the screen.
Adding a Layout - XML example - adding to the layout XML
The layout xml is placed in <project_path>/res/layouts
Adding a Layout - Code example
This would be implemented in an Activity class.
Global Strings
A global string, or an array of strings, are declared in an external xml file in the resource folder:<project>/res/values/strings.xml
Declaring a global string
Using a global string while creating a TextView
Code usage
Code usage
Menus
Options Menu
An Options menu is presented when the user presses the menu button while the Activity is active.
Step 1 - Creating the menu XML
The layout xml is placed in <project_path>/res/menu
Step 2 – Displaying the menu (implemented in Activity class)
Step 3 – Listening to user choice (implemented in Activity class)
Context Menu
A context menu is a floating list of menu items that appears when the user performs a long-press on a View.
Step 1 - Creating a menu XML
Step 2 – Showing the menu (implemented in Activity class)
Step 3 – Listening to user choice (implemented in Activity class)
Step 4 – Attaching the context menu to a view (implemented in Activity class)
![Context Menu](images/contextmenu.jpg)
Submenu
A submenu is a floating list of menu items that the user opens by pressing a menu item in the Options Menu or a context menu.
Alerts/Dialogs
Toast
A toast notification is a message that pops up on the surface of the window.
![Alerts Dialogs](/storage/rc-covers/16662-thumb.png)
AlertDialog
![Alert](/storage/rc-covers/16663-thumb.png)
Status-Bar Notifications
One way to notify an Android user is by displaying notifications in the status bar. You can show a message, play a sound, add an icon and more.
Creating a status bar notification
![Status Bar](images/Statusbar.jpg)
Resource Images
Resource images are placed under <project_dir>/res/drawable
Using a resource image in an image view - XML example
Turning the resource image to a Bitmap object
Drawing the bitmap on a canvas object
Creating Links Using Linkfy
Linkfy is a class that lets you create links from TextViews.
You can create links not just to web sites, but to also map addresses, emails and even phone numbers.
Creating web links
![Hot Tip](/storage/rc-covers/16664-thumb.png)
You can also create links to phone numbers, map locations or email addresses.
Using a regular expressionfor filtering strings