0
我創建了一個應用程序,它使用appcompat v21庫來獲取棒棒糖設備上的材質外觀。
這個程序用於工作,直到我將手機升級爲棒棒糖。現在它運行時崩潰。
的錯誤信息是:棒棒糖上的Appcompat崩潰
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
然而,據我所看到的,我使用的程序兼容性主題無處不在。
活動佈局:
<include layout="@layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:foreground="?android:windowContentOverlay"/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="480dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:background="@color/primaryBackground"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:listSelector="@color/listSelectedItem" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
工具欄佈局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
樣式:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:activatedBackgroundIndicator">@drawable/list_selector</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
<style name="MyActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">@color/primaryColor2</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="background">@color/primaryColor2</item>
<item name="windowActionBarOverlay">true</item>
</style>
</resources>
我在做什麼錯?
乾杯, CJ
編輯: 新增清單
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:name=".MusicViewerApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/myAppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SetlistConcertActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/title_activity_setlist"
android:screenOrientation="portrait" >
</activity>
</application>
</manifest>
EDIT2:樣式添加-V21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myAppTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="android:statusBarColor">@color/primaryColorDark</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:activatedBackgroundIndicator">@drawable/list_selector</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
</resources>
你有沒有在你的清單中聲明它? – rubberdont
您是否使用值'值-v21'或不。 – Yugesh
發佈您的清單文件,否則告訴我們您在清單文件中使用了哪個主題? –