随着appTheme动作栏消失,为什么?

时间:2016-06-15 09:49:46

标签: android xml android-actionbar android-fragmentactivity

我的主要活动扩展 FragmentActivity ,如果我使用默认应用主题,则操作栏消失

样式:     

<!-- 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>

在Manifest中使用样式:

enter image description here

在Android清单中

没有android:theme =“@ style / AppTheme”:

enter image description here

我尝试在 FragmentActivity 中使用 getActionBar()。show(),但它只返回null。为什么会发生这种情况?如何使用样式打开操作栏

2 个答案:

答案 0 :(得分:1)

您需要主类来扩展AppCompatActivity,而不是扩展FragmentActivity。

有关详细信息,请参阅That

答案 1 :(得分:0)

试试这个

<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/