Theme.AppCompat.Light.DarkActionBar导致没有显示ActionBar

Don*_*mmy 15 android android-studio android-styles

我在Android Studio中创建了一个带有空白活动的项目(然后编写代码以放入基本片段 - 空线性布局),但没有显示ActionBar.为什么?

设备:仿真器(Nexus 5尺寸),API 19

主要活动延伸FragmentActivity.

Android Studio生成了styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

活动布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/fragmentContainer"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)

片段:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)

表现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.test" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".TestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

Don*_*mmy 28

FragmentActivity我需要扩展主类,而不是扩展AppCompatActivity.

如下所述:

http://developer.android.com/training/basics/fragments/creating.html

如果您正在使用v7 appcompat库,那么您的活动应该扩展ActionBarActivity,它是FragmentActivity的子类(有关更多信息,请参阅添加操作栏).

编辑

ActionBarActivity 现已弃用.请AppCompatActivity改用.