带有 appTheme 的操作栏消失了,为什么?

with appTheme actionbar disappears, why?

我的主要 Activity 扩展 FragmentActivity 如果我使用默认应用主题,actionbar 会消失

风格:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowActionBar">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

清单中的样式:

Android 清单中没有 android:theme="@style/AppTheme":

我尝试在 FragmentActivity 中使用 getActionBar().show() 但它只是 returns 无效的。为什么会发生这种情况以及如何使用样式打开 actionbar

这样试试

<resources>
    <style name="CustomMaterialTheme" parent="CustomMaterialTheme.Base">
    </style>
    <style name="CustomMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:windowBackground">@color/windowBackground</item>     
    </style>
</resources>

然后在清单中使用主题。参考这里:http://coderzpassion.com/android-working-with-material-design/

无需扩展 FragmentActivity,您需要主要 class 扩展 AppCompatActivity。

有关详细信息,请参阅 That