Android入门之支持不同的设备

时间:2014-01-21 00:16:55   收藏:0   阅读:495

支持不同的设备包括:

一、支持不同的语言

应用程序中的UI部分字符串定义在res/values/strings.xml文件中,这是一个很好的习惯!

MyProject/
    res/
       values/
           strings.xml
       values-es/
           strings.xml
       values-fr/
           strings.xml
不同的语言要放在合适的目录下,例如:

English (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>

Spanish, /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>

French, /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>

二、支持不同的屏幕尺寸及分辨率

三、支持不同的系统平台版本

指定最小和目标API级别:

 AndroidManifest.xml 中

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>

    <uses-sdkandroid:minSdkVersion="4"android:targetSdkVersion="15"/>

    ...

</manifest>

2、在运行时检查系统版本:

private void setUpActionBar(){

    // Make sure we‘re running on Honeycomb or higher to useActionBar APIs

    if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.HONEYCOMB){

        ActionBar actionBar= getActionBar();

        actionBar.setDisplayHomeAsUpEnabled(true);

    }

}

3、使用平台风格和主题:

使用对话框主题:

<activity android:theme="@android:style/Theme.Dialog">

使用透明背景的主题:

<activity android:theme="@android:style/Theme.Translucent">

 /res/values/styles.xml 下定义自己的风格主题:

<activity android:theme="@style/CustomTheme">

如果要定义所有页面的风格主题,则把 android:theme 添加到<application> 元素中:

<applicationandroid:theme="@style/CustomTheme">

更多风格和主题可以看http://developer.android.com/guide/topics/ui/themes.html


原文:http://blog.csdn.net/jkxqj/article/details/18375371

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!