我已經成功地在Eclipse中創建了一個應用程序,它適用於Android 4.0及以上版本。現在我想讓它兼容android 2.3及更高版本。在我的應用程序中,我使用了操作欄,因此我在工作區中的工作集中添加了android-support-v7-appcompat庫項目。在遵循http://developer.android.com/tools/support-library/setup.html指示之後,現在我已在我的項目Android Private Libraries部分下有'android-support-v7-appcompat.jar'和'android-support-v4.jar'。此外,我有我的項目的libs文件夾下的jar文件。應用程序崩潰時,爲Android 2.3及以上版本實施Action Bar支持v7庫
在我的主要活動中,我輸入:
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
在AndroidManifest.xml文件,我宣佈:
<application android:allowBackup="true"
android:theme="@style/Theme.AppCompat"
此外,對於不同的活動,聲明如下:
<activity android:
android:uiOptions="splitActionBarWhenNarrow"
以前我的AndroidManifest.xml是這樣的:
<application android:allowBackup="true"
android:theme="@style/<theme>"
和下RES的styles.xml>值的文件夾是這樣的:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="<base>" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="<theme>" parent="<base>">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
在值中使用
<style name="<base>" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
在值-V11夾
和
<style name="<base>" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
-v14文件夾。
我現在已經囊括了所有的styles_base.xml和庫項目到我的項目themes_base.xml文件。還通過將Theme替換爲更改了styles.xml文件。
我每次運行應用程序時,我面對崩潰,現在連4.0及更高版本的Android版本。該消息:
java.main.NoClassDefFounderError: android.support.v7.appcompat.R$styleable
at android.support.v7.app.ActionBarActivityDelegate.onCreate
請幫忙。
我檢查了項目屬性 - > Java構建路徑 - >訂單和導出部分。 android-support-v4.jar和android-support-v7-appcompat.jar文件都在那裏。但是每個jar文件都有兩次。一個顯示位置作爲我的項目庫,另一個顯示我下載庫項目的位置。還有一件事,這些jar文件都沒有被檢查,只有Android Dependencies被選中。我需要在這裏做任何改變嗎? – MSIslam
我很驚訝有兩個相同的lib實例沒有錯誤。你應該嘗試:1.刪除重複,所以只有一個實例存在; 2.檢查兩者; 3.清理並運行項目 – Kai
感謝您的建議。只是爲了確保在刪除jar文件之前,在我的項目中,我在Android Private Libraries部分下有這些jar文件,並且還有我的項目的libs文件夾下的jar文件。我應該刪除哪一個?另外,是否需要在項目屬性 - > Java構建路徑 - >訂單和導出部分取消選中Android依賴關係? – MSIslam