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

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

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

問題描述

我想使用 SDK 11 中包含的操作欄功能.但是,我還希望該應用能夠在 SDK 10 (2.3.3) 的早期設備上運行.我愿意放棄早期設備的操作欄功能,因為它不是一個重要的功能.我已經閱讀了有關反射、包裝類和其他一些技術的所有內容.我現在對如何完成這項工作感到困惑.我正在使用 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.

如果我沒有將 Eclipse 中的目標設置為 sdk 11 或更高版本,那么我引用 actionBar 的任何地方都會出現編譯錯誤.如果我將目標設置為 sdk 11 或更高版本,它會編譯但不會顯示它可以在早期設備上運行.我一直設置 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.

有人能給我一些關于如何引用 actionBar 并讓它針對以前的 sdk 級別的見解嗎?提前致謝.

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.

推薦答案

是的!你絕對可以做到這一點.嘗試遵循下面概述的模式.

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

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

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" />

通過針對 API 11 或更高版本的平臺版本,您允許 Eclipse 鏈接(編譯)本機 ActionBar 類.提供較早的最低平臺版本可讓您的應用在較早版本的 Android 上安裝(運行).

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.

您的活動代碼應如下所示:

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 類僅提供靜態輔助方法來確定 SDK 的當前版本:

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 庫,它提供了一個兼容的 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:

庫將自動使用本機操作欄可用或將自動包裝自定義實現你的布局.這使您可以輕松地開發具有回溯至 2.x 的每個 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.

玩得開心!

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

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

相關文檔推薦

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 存儲桶身份驗證錯誤)
admob 6.2.1 nullpointer exception(admob 6.2.1 空指針異常)
How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中設置 SDK?)
My phone cannot be detected in eclipse to test run(eclipse 無法檢測到我的手機進行試運行)
platform-toolsaapt.exe directory missing in android SDK(android SDK 中缺少 platform-toolsaapt.exe 目錄)
主站蜘蛛池模板: 黄色片在线观看网址 | 国产精品a久久久久 | 91人人爽| 久久国产精品亚洲 | 亚洲综合激情 | 久久久久久久国产精品视频 | 理论片87福利理论电影 | 欧美国产日韩在线观看 | 亚洲精品一区在线 | 国产精品乱码一区二三区小蝌蚪 | 中文字幕第一页在线 | www.99久久.com| 美女黄视频网站 | 成人在线看片 | 毛片免费在线观看 | 婷婷久久久久 | 精品无码久久久久久久动漫 | 国产精品欧美日韩 | 亚洲 欧美 在线 一区 | 国产日韩欧美精品一区二区三区 | 日本久久综合 | 91亚洲国产成人久久精品网站 | 夜夜精品视频 | 国产精品久久久久久av公交车 | 午夜精品一区二区三区免费视频 | 黄色免费在线网址 | 日韩av一区二区在线观看 | 欧美高清视频在线观看 | 国产精品av久久久久久久久久 | 久久成人人人人精品欧 | 国产精品一二三区在线观看 | 国产精品高潮呻吟久久aⅴ码 | 亚洲精品一区二区三区蜜桃久 | 国产在线中文字幕 | av一级久久| 国产不卡视频 | caoporn视频 | 一区二区三区欧美 | 久久国产婷婷国产香蕉 | 精品视频成人 | 成人国产精品久久 |