官网地址
http://developer.android.com/training/basics/supporting-devices/index.html
一、支持不同的语言
和其它程序一样,通常为了支持多种语言,需要额外写一份资源文件。
新建一个和values目录同级的values-zh的文件夹,将里面strings的值都写成中文
比如,原来是这样
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">MyFirstApp</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string name="edit_message">Entry a message</string> <string name="button_send">Send</string> <string name="title_activity_display_message">DisplayMessageActivity</string> <string name="action_search">Search</string> </resources>
修改后成这样
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">我的应用</string> <string name="action_settings">设置</string> <string name="hello_world">你好,世界</string> <string name="edit_message">输入一个消息</string> <string name="button_send">发送</string> <string name="title_activity_display_message">显示消息</string> <string name="action_search">查询</string> </resources>
图片国际化,类似。
二、支持不同的屏幕分辨率
为了支持不同屏幕的分辨率,首先要创建不同的layout ,和资源文件差不多,也是在相同目录下新建不同的文件夹,如layout ,layout-large,layout-land ....
然后创建不同的位图资源,其实在创建项目的时候Eclipse已经为我们创建了,如
drawable-hdpi,drawable-ldpi,drawable-mdpi ....
三、支持不同平台
1. SDK
在创建项目的时候就有最小支持SDK版本,和目标SDK版本,项目创建好后在清单文件AndroidManifest.xml中<uses-sdk>里有相应的设置
2.在运行时检查系统版本
private void setUpActionBar() { // Make sure we're running on Honeycomb or higher to use ActionBar APIs if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); } }
3. 使用样式和主题
//To make your activity look like a dialog box: <activity android:theme="@android:style/Theme.Dialog"> //To make your activity have a transparent background: <activity android:theme="@android:style/Theme.Translucent"> //To apply your own custom theme defined in /res/values/styles.xml: <activity android:theme="@style/CustomTheme"> //To apply a theme to your entire app (all activities), add the android:theme //attribute to the <application> element: <application android:theme="@style/CustomTheme">
很简单吧