我正在關注Android培訓,在造型操作欄中。造型操作欄使用Theme.AppCompat
我面臨錯誤,因爲android:[email protected]/MyActionBar
。
我想知道如何風格的行動欄。
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyActionBar" >
IllegalStateException: You need to use a Theme.AppCompat theme with this activity
我認爲該錯誤:
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
,所以我將它修改爲
<style name="CustomActionBarTheme"
parent="@android:style/Theme.AppCompat.Light ">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
我有以下錯誤:
error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat.Light '.
我創建了一個新的文件作爲培訓解釋
RES /價值/的themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#aaaaaa</item>
</style>
</resources>
這裏是清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyActionBar" >
<activity
android:name="com.example.helloworld.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="com.example.helloworld.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.Helloworld.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.Helloworld.MyActivity" />
</activity>
</application>
</manifest>
您是否已將庫添加到項目屬性中? – Harry 2015-04-03 11:27:47