创建本地目录和字符串文件
MyProject/
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml 使用字符串的方法:
// Get a string resource from your app'sResourcesString hello =getResources().getString(R.string.hello_world); // Or supply a string resource to a method that requires a string TextView textView = new TextView(this); textView.setText(R.string.hello_world);
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" />
使用平台样式和主题
<activity android:theme="@android:style/Theme.Dialog">
指明 Minimum 和 Target API
AndroidManifest.xml 中<uses-sdk的 minSdkVersion 和 targetSdkVersion 属性指明app的最低平台版本和最高平台版本.
<manifest xmlns:android="/apk/res/android" ... > <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" /> ... </manifest>
Tip: 在app中使用 Android Support Library 可获得更好的跨平台体验,使得新的api可以在旧版本上运行。
在运行时判断当前版本
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); } }
指明为不同屏幕创建布局和图像
MyProject/
res/
layout/ # default (portrait)
main.xml
layout-land/ # landscape
main.xml
layout-large/ # large (portrait)
main.xml
layout-large-land/ # large landscape
main.xml
MyProject/
res/
drawable-xhdpi/
awesomeimage.png
drawable-hdpi/
awesomeimage.png
drawable-mdpi/
awesomeimage.png
drawable-ldpi/
awesomeimage.png 不同屏幕的比例
- xhdpi: 2.0
- hdpi: 1.5
- mdpi: 1.0 (baseline)
- ldpi: 0.75提供了hdpi尺寸的图像时,如果没有提供ldpi的,将缩放hdpi的图像50%使用(很不错)
Tip: In order to provide the best features and functionality across several Android versions, you should use the Android Support Library in your app, which allows you to use several recent platform APIs on older versions.
- xhdpi: 2.0
- hdpi: 1.5
- mdpi: 1.0 (baseline)
- ldpi: 0.75

这篇博客详细介绍了如何在Android应用中进行多语言、多屏幕尺寸和多平台版本的支持,包括创建本地目录和字符串文件、利用平台样式和主题、设置Minimum和Target API,以及为不同屏幕定制布局和图像。建议使用Android Support Library来实现更好的向下兼容性。
286

被折叠的 条评论
为什么被折叠?



