This document provides an overview of Android training session 2 which covers UI design, layouts, activities, and intents. It discusses common layouts like linear and relative layouts. It also discusses layouts that use adapters like grid views and list views. Additionally, it covers topics like drawables, styles, themes, menus, and the activity lifecycle. It provides examples of using explicit and implicit intents to start activities and examples of handling the activity lifecycle.
9. RELATIVE LAYOUT
• android:layout_alignParentTop
– If "true", makes the top edge of this view match the top edge of the
parent.
• android:layout_centerVertical
– If "true", centers this child vertically within its parent.
• android:layout_below
– Positions the top edge of this view below the view specified with a
resource ID.
• android:layout_toRightOf
– Positions the left edge of this view to the right of the view specified
with a resource ID.
These are just a few examples. All layout attributes are documented at
RelativeLayout.LayoutParams.
22. STYLES
• Inheritance – by adding parent it can be inherited:
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
• If the parent is your style then don’t use parent, Just make the prefix:
<style name="CodeFont.Red">
<item name="android:textColor">#FF0000</item>
</style>
[refrence will be : @style/CodeFont.Red.]
• You can continue inheritance this way:
<style name="CodeFont.Red.Big">
<item name="android:textSize">30sp</item>
</style>
23. THEMES
• To set a theme for all the activities of your application, open the
AndroidManifest.xml file and edit the <application> tag to include the
android:theme attribute with the style name. For example:
• If you want a theme applied to just one Activity in your application, then
add the android:theme attribute to the <activity> tag instead.
24. THEMES
• If you like a theme, but want to tweak it, just add the theme as the parent
of your custom theme. For example, you can modify the traditional light
theme to use your own color like this:
• Now use CustomTheme instead of Theme.Light inside the Android
Manifest:
• Android Styles (styles.xml)
• Android Themes (themes.xml)
25. MENU
• Beginning with Android 3.0 (API level 11), the action bar is included
• If you've created a custom theme, be sure it uses one of the Theme.Holo
themes as its parent. For details, see Styling the Action Bar.
• Adding the action bar when running on versions older than Android 3.0
(down to Android 2.1 [API level 7]) requires that you include the Android
Support Library in your application.
• Update your activity so that it extends ActionBarActivity. For example:
• In your manifest file, update either the <application> element or individual
<activity> elements to use one of the Theme.AppCompat themes. For
example:
26. MENU / ACTION BAR
• Adding Action Buttons
• Specify the Actions in XML
27. MENU / ACTION BAR
• If your app is using the Support Library, the showAsAction attribute is not
available from the android: namespace.
[NB: A custom XML namespace should be based on your app name, but it
can be any name you want and is only accessible within the scope of the file
in which you declare it.]
28. MENU / ACTION BAR
• Add the Actions to the Action Bar:
30. MENU / ACTION BAR
• Add Up Button for Low-level Activities like as:-
• Add the Parent Activity for a child activity as bellow:
31. NINE-PATCH
• Launch the draw9patch
application from your SDK /tools
directory
• File > Open 9-patch... to locate the
file
• Click within the 1-pixel perimeter to
draw the lines that define the
stretchable patches and (optional)
content area. Right-click (or hold Shift
and click, on Mac) to erase previously
drawn lines.
• When done, select File > Save 9-
patch... Your image will be saved with
the .9.png file name.
33. ACTIVITY
• Specify Your App's Launcher Activity
• You need to know all that facts clearly for better designing the Application:
– Does not crash if the user receives a phone call or switches to another app while using
your app.
– Does not consume valuable system resources when the user is not actively using it.
– Does not lose the user's progress if they leave your app and return to it at a later time.
– Does not crash or lose the user's progress when the screen rotates between landscape
and portrait orientation.
36. INTENT
• Explicit Intent:
– We generally do so with an explicit intent, which defines the exact class name of the
component you want to start.
• Implicite Intent:
– when we want to have a separate app perform an action, such as "view a
map," you must use an implicit intent.
37. IMPLICITE INTENT
• View a web page:
• To make a phone call from your app:
• Send an email with an attachment:
38. IMPLICITE INTENT
• Caution: If you invoke an intent and there is no app available on the device
that can handle the intent, your app will crash.
• To verify there is an activity available that can respond to the intent, call
queryIntentActivities() to get a list of activities capable of handling your
Intent. If the returned List is not empty, you can safely use the intent. For
example:
• Please see details at here.