久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Android SDK 中編寫(xiě)向后兼容的新功能?

How to code backward compatible new feature in Android SDK?(如何在 Android SDK 中編寫(xiě)向后兼容的新功能?)
本文介紹了如何在 Android SDK 中編寫(xiě)向后兼容的新功能?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我想使用 SDK 11 中包含的操作欄功能.但是,我還希望該應(yīng)用能夠在 SDK 10 (2.3.3) 的早期設(shè)備上運(yùn)行.我愿意放棄早期設(shè)備的操作欄功能,因?yàn)樗皇且粋€(gè)重要的功能.我已經(jīng)閱讀了有關(guān)反射、包裝類(lèi)和其他一些技術(shù)的所有內(nèi)容.我現(xiàn)在對(duì)如何完成這項(xiàng)工作感到困惑.我正在使用 Eclipse.

I want to use the actionbar feature included in SDK 11. However I also want the app to run on earlier devices from SDK 10 (2.3.3). I am willing to give up the actionbar feature for the earlier devices as it is not an important feature. I have done all the reading about reflection, wrapper class and some other techniques. I am now stumped on exactly how to make this work. I am using Eclipse.

如果我沒(méi)有將 Eclipse 中的目標(biāo)設(shè)置為 sdk 11 或更高版本,那么我引用 actionBar 的任何地方都會(huì)出現(xiàn)編譯錯(cuò)誤.如果我將目標(biāo)設(shè)置為 sdk 11 或更高版本,它會(huì)編譯但不會(huì)顯示它可以在早期設(shè)備上運(yùn)行.我一直設(shè)置 android:minSdkVersion=10.

If I don't set the target in Eclipse to sdk 11 or greater, then any place I have a reference to actionBar gives a compile error. If I put the target to sdk 11 or greater it compiles but won't show that it can run on earlier devices. I have android:minSdkVersion=10 set all the time.

有人能給我一些關(guān)于如何引用 actionBar 并讓它針對(duì)以前的 sdk 級(jí)別的見(jiàn)解嗎?提前致謝.

Can someone give me some insight on how to make the references to actionBar and yet get it to target a previous sdk level? Thanks in advance.

推薦答案

是的!你絕對(duì)可以做到這一點(diǎn).嘗試遵循下面概述的模式.

Yes! You can definitely do this. Try following the pattern outlined below.

在您的 AndroidManifest.xml 文件中聲明以下內(nèi)容(將平臺(tái)版本替換為您的應(yīng)用所需的任何版本):

In your AndroidManifest.xml file declare the following (replacing the platform versions with whatever your app requires):

<!-- Build Target -->
<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="7" />

通過(guò)針對(duì) API 11 或更高版本的平臺(tái)版本,您允許 Eclipse 鏈接(編譯)本機(jī) ActionBar 類(lèi).提供較早的最低平臺(tái)版本可讓您的應(yīng)用在較早版本的 Android 上安裝(運(yùn)行).

By targeting a platform version of API 11 or higher, you are allowing Eclipse to link (compile) against the native ActionBar classes. Providing an earlier minimum platform version allows your app to be installed (run) on older versions of Android.

您的活動(dòng)代碼應(yīng)如下所示:

Your Activity code should then look something like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (CompatibilityManager.isHoneycomb()) {
        final ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowHomeEnabled(true);
        // ...
    } else {
        // The ActionBar is unavailable!
        // ...
    }
}

CompatibilityManager.java 類(lèi)僅提供靜態(tài)輔助方法來(lái)確定 SDK 的當(dāng)前版本:

Where the CompatibilityManager.java class simply provides static helper methods for determining the current version of the SDK:

public class CompatibilityManager {
    public static final String KINDLE_FIRE_MODEL = "Kindle Fire";

    /**
     * Get the current Android API level.
     */
    public static int getSdkVersion() {
        return android.os.Build.VERSION.SDK_INT;
    }

    /**
     * Determine if the device is running API level 11 or higher.
     */
    public static boolean isHoneycomb() {
        return getSdkVersion() >= Build.VERSION_CODES.HONEYCOMB;
    }

    /**
     * Determine if the device is running API level 14 or higher.
     */
    public static boolean isIceCreamSandwich() {
        return getSdkVersion() >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
    }

    /**
     * Determine if the current device is a first generation Kindle Fire.
     * @return true if the device model is equal to "Kindle Fire", false if otherwise.
     */
    public static boolean isKindleFire() {
        return Build.MODEL.equals(KINDLE_FIRE_MODEL);
    }
}

您還可以考慮利用 ActionBarSherlock 庫(kù),它提供了一個(gè)兼容的 ActionBar API,可以追溯到 Android 2.x:

You might also consider leveraging the ActionBarSherlock library, which provides a compatible ActionBar API all the way back to Android 2.x:

庫(kù)將自動(dòng)使用本機(jī)操作欄可用或?qū)⒆詣?dòng)包裝自定義實(shí)現(xiàn)你的布局.這使您可以輕松地開(kāi)發(fā)具有回溯至 2.x 的每個(gè) Android 版本的操作欄.

The library will automatically use the native action bar when available or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android back through 2.x.

玩得開(kāi)心!

這篇關(guān)于如何在 Android SDK 中編寫(xiě)向后兼容的新功能?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why would you choose Android API over Google APIs in the SDK on Eclipse?(為什么在 Eclipse 的 SDK 中選擇 Android API 而不是 Google API?)
Couchbase Bucket authentication error(Couchbase 存儲(chǔ)桶身份驗(yàn)證錯(cuò)誤)
admob 6.2.1 nullpointer exception(admob 6.2.1 空指針異常)
How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中設(shè)置 SDK?)
My phone cannot be detected in eclipse to test run(eclipse 無(wú)法檢測(cè)到我的手機(jī)進(jìn)行試運(yùn)行)
platform-toolsaapt.exe directory missing in android SDK(android SDK 中缺少 platform-toolsaapt.exe 目錄)
主站蜘蛛池模板: 97人人爱 | 青青草原综合久久大伊人精品 | 日韩中文在线 | 欧美在线综合 | 天堂视频免费 | 国产精品7777777 | 蜜桃视频一区二区三区 | 亚洲欧美日韩精品 | 手机看片在线播放 | 99在线国产 | av一区二区三区 | www..99re| 九九精品在线 | 草久久免费视频 | 综合久久久 | 午夜影院在线观看视频 | 亚洲第一成人av | 成人性生交大片免费看r链接 | 欧美日韩亚洲视频 | 国产精品久久久久一区二区三区 | 亚洲最新网址 | 日韩在线小视频 | 午夜国产 | 三级视频在线观看电影 | 国产a级黄色录像 | 一区二区视频在线 | 免费看a | 日本特黄特色aaa大片免费 | 一区二区三区四区av | 热re99久久精品国99热观看 | 91久久精品国产91久久性色tv | 国产精品特级毛片一区二区三区 | 国产视频一区二区在线观看 | 国产精品久久久久久久白浊 | av在线免费播放 | 国产精品久久久久久久久久 | 久久久久成人精品免费播放动漫 | 欧美久久一区二区三区 | 超碰人人爱 | av片网 | 毛片区 |