问题描述
在处理Big Nerd Ranch的犯罪意图项目时,我将AppCompat库从API 19更新为API 21时,我丢失了ActionBar.我尝试过改变主题,但是找不到找到ActionBar的方法.
While working on the Big Nerd Ranch's Criminal Intent project when I updated my AppCompat library from API 19 to API 21 I lost ActionBar. I have tried changing themes around but I can't find a way to get ActionBar.
完整的源代码可在此处.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sudhirkhanger.app.criminalintent" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".CrimeListActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CrimePagerActivity"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
谢谢.
推荐答案
要使用appcompat-v7
,您必须继承自ActionBarActivity
. CrimeListActivity
继承自SingleFragmentActivity
,而SingleFragmentActivity
继承自FragmentActivity
,而不是ActionBarActivity
.
To use appcompat-v7
, you must inherit from ActionBarActivity
. CrimeListActivity
inherits from SingleFragmentActivity
, which in turn inherits from FragmentActivity
, not ActionBarActivity
.
这篇关于切换到API21 AppCompat后缺少ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!