1.支持不同的语言
在 Android 工程的目录下,res/values/strings.xml的文件来保存字符串值。
如果你没有建立多个不同的values文件夹,系统默认会加载 /values/strings.xml 文件中的值。
// 西班牙
Spanish, /values-es/strings.xml
// 法国
French,/values-fr/strings.xml
我们可以通过R.string.xxx,strings.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 中你可以这样使用
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
2.支持不同的屏幕
安卓设备的分类是由大小和密度决定的。
四种大小:small, normal, large, xlarge
四种密度: 低(ldpi), 中(mdpi), 高(hdpi), 特高(xhdpi)
注意:屏幕的旋转是被认为屏幕尺寸的改变。
MyProject/
res/
默认加载的 layout/
main.xml
大屏幕加载的 layout-large/
main.xml
横屏加载的 layout-land/
main.xml
默认情况下,layout/main.xml 是加载竖屏的
关于生成不同的图片,有这样四个转换的参数
xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75
这个意味着,如果你在 xhdpi 上生成一张 200 x 200 的图片,在hdpi上就是 150 x 150,在 mdpi 上就是 100 x 100,在 ldpi 上就是 75 x 75。
3.支持不同的平台版本
Build 常量类,用来判断 Android 的平台版本。
一些主题的使用和怎样自定义主题。