【问题标题】:with appTheme actionbar disappears, why?随着 appTheme 动作栏消失,为什么?
【发布时间】:2016-06-15 09:49:45
【问题描述】:

我的主 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>

Manifest 中的样式:

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

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

【问题讨论】:

  • 解释“清单中的样式”? Actionbar 仅由 Theme 控制。
  • FragmentActivity 更改为 AppCompatActivity... 也使用 getSupportActionBar().show();

标签: android xml android-actionbar android-fragmentactivity


【解决方案1】:

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

更多详情见That

【讨论】:

    【解决方案2】:

    这样试试

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      相关资源
      最近更新 更多