您的位置:首页 > 移动开发 > Android开发

Android支持不同Devices

2012-08-12 09:55 99 查看
2 Support Different Language

首先要把相关的字符串都写到 res/values/strings.xml 文件里,想支持几种语言就建几个目录,像 valus-es,

其中 es 指ISO country code(暂时不用细查)

MyProject/

res/

values/

strings.xml

values-es/

strings.xml

values-fr/

strings.xml

如何引用 strings.xml中的定义的string呢,分为两种情况,一种是在代码中使用,另一种是在其它xml中使用:

在代码中使用:

// Get a string resource from your app's Resources

String 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);

在其它xml中使用:(@string/<string_name>)

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world" />

3 Support Different Screen

screen sizes: small, normal, large, xlarge

densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)

如果你想Activity的layout随着屏幕大小或者横纵屏而不同的话,那么就需要建立

layout-land(横屏),layout_large(大屏),layout-large-land(大屏的横屏),这些目录,它们都是

相对于layout目录来说的,layout目录默认为纵屏。

drawable-*dpi目录是用来存 bitmap的,即程序的icon,对于不同的density来说,icon的分辨率比率为:

xhdpi: 2.0

hdpi: 1.5

mdpi: 1.0 (baseline)

ldpi: 0.75

4 Supporting Different Platform Versions

版本 代号 API等级

1.5 Cupcake 3

1.6 Donut 4

2.1 Eclair 7

2.2 Froyo 8

2.3.3 Gingerbread 10

3.0 Honeycomb 11

3.1 12

3.2 13

4.0 Ice Cream Sandwich 14

4.0.3 15

4.1 16

下面是官方文档上的一个截图



在AndroidManifest.xml中设置 uses-sdk

在代码中检测Android版本的方法:

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);

}

}

<activity android:theme="@android:style/Theme.Dialog"> (使用系统的)

<activity android:theme="@style/CustomTheme"> (使用自定义的)

再说Style和Theme

style 是用来指定 "View" 的,如背景是什么,字体是什么颜色

Theme 是用来指定"Activity及Application"的(style也可以用作Theme,这时整个Activity中的View都会应用这种style)

系统提供的built-in style和theme可以查看 R.style类.(可以查看原代码styles.xml,themes.xml)

当自己定义style时,可用的 style attributes 可以查看 R.attr或各View class 的说明文档

当定义主题的 attributes 可以查看 R.styleable.Theme
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: