切换到API21 AppCompat后缺少ActionBar [英] ActionBar is missing after switching to API21 AppCompat

查看:80
本文介绍了切换到API21 AppCompat后缺少ActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆