Theme.AppCompat.Light.DarkActionBar не приводит к показу ActionBar
Я создал проект с пустой активностью (а затем написал код, чтобы положить в базовый фрагмент - пустой линейный макет) в 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>
Схема действий:
<?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" />
Фрагмент:
<?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" />
манифеста:
<?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>
Ответы
Ответ 1
Вместо расширения FragmentActivity
мне нужен основной класс для расширения AppCompatActivity
.
Как объясняется здесь:
http://developer.android.com/training/basics/fragments/creating.html
Если вы используете библиотеку appcompat v7, ваша активность должна расширять ActionBarActivity, что является подклассом FragmentActivity (для получения дополнительной информации см. "Добавление панели действий" ).
ИЗМЕНИТЬ
ActionBarActivity
теперь устарел. Вместо этого используйте AppCompatActivity
.