Android session 2-behestee


Published on

Android Training session at Jaxara IT

Published in: Education, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Android session 2-behestee

  1. 1. ANDROID TRAINING SESSION – 2 -Hussain KMR Behestee
  2. 2. AGENDAS • UI Design for Android – Layout – Drawable • Activity • Intent – Explicit Intent – Implicite Intent
  4. 4. UI DESIGN FOR ANDROID • Layout – Common layout • Linear layout • Relative layout – Layout with adapter • Grid View • List View
  5. 5. LAYOUT
  6. 6. COMMON LAYOUT Linear Relative
  9. 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.
  10. 10. LAYOUT WITH ADAPTER Grid View List View
  11. 11. GRIDS
  12. 12. GRIDS
  13. 13. LIST
  14. 14. LIST Creating adapter Setting adapter Adding click listener
  15. 15. UI DESIGN FOR ANDROID • Drawables – State List • Drawable / Color – Styles – Themes – Menu – Nine-Patch
  16. 16. STATE LIST — android:state_pressed — android:state_focused — android:state_hovered — android:state_selected — android:state_checkable — android:state_checked — android:state_enabled — android:state_activated — android:state_window_focused
  17. 17. DRAWABLE / COLOR • android:drawable – Drawable resource. Required. Reference to a drawable resource • android:color – Hexadeximal color. Required. RGB value or Alpha- Red-Green-Blue
  18. 18. DRAWABLE / COLOR android:drawable - File name with res/drawable/button.xml
  19. 19. DRAWABLE / COLOR android:color - File name with res/color/buttontext.xml
  20. 20. DRAWABLE / COLOR
  21. 21. STYLES Inline styles Styles definition Using style
  22. 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. 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. 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. 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. 26. MENU / ACTION BAR • Adding Action Buttons • Specify the Actions in XML
  27. 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. 28. MENU / ACTION BAR • Add the Actions to the Action Bar:
  29. 29. MENU / ACTION BAR • Respond to Action Buttons:
  30. 30. MENU / ACTION BAR • Add Up Button for Low-level Activities like as:- • Add the Parent Activity for a child activity as bellow:
  31. 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.
  32. 32. ACTIVITY • Understand the Lifecycle Callbacks
  33. 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.
  34. 34. ACTIVITY • Save Your Activity State
  35. 35. ACTIVITY • Restore Your Activity State
  36. 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. 37. IMPLICITE INTENT • View a web page: • To make a phone call from your app: • Send an email with an attachment:
  38. 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.
  39. 39. QUESTION?
  40. 40. THANK YOU