Your SlideShare is downloading. ×
Android App Development 08 : Support Multiple Devices
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Android App Development 08 : Support Multiple Devices


Published on

Published in: Technology, News & Politics

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. 8 Support Different Devices Anuchit Chalothorn anoochit@gmail.comLicensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 2. Supporting Different LanguagesAndroid will run on many devices in manyregions. To reach the most users, yourapplication should handle text, audio files,numbers, currency, and graphics in waysappropriate to the locales where yourapplication will be used.
  • 3. Using Resources for LocalizationThe default resource set must also include anydefault drawables and layouts, and can includeother types of resources such as animations.● res/drawable/● res/layout/● res/anim/● res/xml/● res/raw/
  • 4. Language StringAndroid makes this easy with a resourcesdirectory in each Android project. Within theres/ directory are subdirectories for variousresource types. There are also a few defaultfiles such as res/values/strings.xml, whichholds your string values.
  • 5. Locale Directories and String FilesTo add support for more languages, createadditional values directories inside res/ thatinclude a hyphen and the ISO country code atthe end of the directory name. eg: values-esfor Spanish, values-th for Thai, values forEnglish etc.
  • 6. Locale : EnglishEnglish (default locale), /values/strings.xml :<?xml version="1.0" encoding="utf-8"?><resources> <string name="title">My Application</string> <string name="hello_world">Hello World!</string></resources>
  • 7. Locale : SpanishSpanish, /values-es/strings.xml :<?xml version="1.0" encoding="utf-8"?><resources> <string name="title">Mi Aplicación</string> <string name="hello_world">Hola Mundo!</string></resources>
  • 8. Locale : FrenchFrench, /values-fr/strings.xml :<?xml version="1.0" encoding="utf-8"?><resources> <string name="title">Mon Application</string> <string name="hello_world">Bonjour le monde !</string></resources>
  • 9. Use the String ResourcesYou can refer to a string resource with thesyntax R.string.<string_name>. There are avariety of methods that accept a string resourcethis way.
  • 10. Use the String Resources// Get a string resource from your apps ResourcesString hello = getResources().getString(R.string.hello_world);// Or supply a string resource to a method that requires astringTextView textView = new TextView(this);textView.setText(R.string.hello_world);
  • 11. Use the String in XMLIn other XML files, you can refer to a stringresource with the syntax@string/<string_name> whenever the XMLattribute accepts a string value.
  • 12. Use the String in XML<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" />
  • 13. Workshop: LocaleCreate form UI like following and make localestring for English, Vietnamese, Japanese andThai.
  • 14. Locale your graphicYou can use qualifiers with any resourcesinclude graphic in drawable directory, eg :● /drawable for English (default locale)● /drawable-th for Thai● /drawable-vn for Vietnamese● /drawable-ja for Japanese
  • 15. Workshop: Locale your graphicCreate a UI like following and make localegraphic for English, Vietnamese, Japanese andThai.
  • 16. Supporting Different ScreensAndroid categorizes device screens using twogeneral properties: size and density. Youshould expect that your app will be installed ondevices with screens that range in both sizeand density.
  • 17. Sizes and DensitiesTo declare different layouts and bitmaps youdlike to use for different screens, you must placethese alternative resources in separatedirectories, similar to how you do for differentlanguage strings.
  • 18. Create Different LayoutsTo optimize your user experience on differentscreen sizes, you should create a unique layoutXML file for each screen size you want tosupport.
  • 19. Create Different LayoutsThe directory named with a -<screen_size>suffix.● /res/layout/main.xml <-- normal● /res/layout-land/main.xml <-- landscape● /res/layout-large/main.xml <-- for large● /res/layout-large-land/main.xml <-- large landscape
  • 20. Create Different BitmapsYou should always provide bitmap resourcesthat are properly scaled to each of thegeneralized density buckets: low, medium, highand extra-high density. This helps you achievegood graphical quality and performance on allscreen densities.
  • 21. Create Different BitmapsTo generate these images, you should startwith your raw resource in vector format andgenerate the images for each density using thefollowing size scale:● xhdpi: 2.0● hdpi: 1.5● mdpi: 1.0 (baseline)● ldpi: 0.75Ref:
  • 22. Workshop: DrawableMake graphic resources match each screensize.
  • 23. Supporting Different Platform VersionsWhile the latest versions of Android oftenprovide great APIs for your app, you shouldcontinue to support older versions of Androiduntil more devices get updated.
  • 24. Specify Minimum and Target APIThe AndroidManifest.xml file describes detailsabout your app and identifies which versions ofAndroid it supports. Specifically, theminSdkVersion and targetSdkVersion with<use-sdk element.
  • 25. Specify Minimum and Target API<manifest xmlns:android="" ... > <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" /> ...</manifest>
  • 26. Check System Version at RuntimeAndroid provides a unique code for eachplatform version in the Build constants class.Use these codes within your app to buildconditions that ensure the code that dependson higher API levels is executed only whenthose APIs are available on the system.
  • 27. Check System Version at Runtimeprivate void setUpActionBar() {// Make sure were running on Honeycomb or higher to useActionBar APIs if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); }}
  • 28. Use Platform Styles and ThemesAndroid provides user experience themes thatgive apps the look and feel of the underlyingoperating system. These themes can beapplied to your app within the manifest file.
  • 29. Platform Styles and ThemesTo make your activity look like a dialog box:<activity android:theme="@android:style/Theme.Dialog">
  • 30. Platform Styles and ThemesTo make your activity have a transparentbackground:To make your activity have atransparent background:<activity android:theme="@android:style/Theme.Translucent">
  • 31. Platform Styles and ThemesTo apply your own custom theme defined in/res/values/styles.xml:<activity android:theme="@style/CustomTheme">
  • 32. Platform Styles and ThemesTo apply a theme to your entire app (allactivities), add the android:theme attribute tothe <application> element:<application android:theme="@style/CustomTheme">
  • 33. End