android:windowNoTitle不会使用appcompat-v7 21.0.0隐藏操作栏

时间:2014-11-12 02:44:35

标签: android android-5.0-lollipop android-appcompat

我将appcompat-v7更新为lollipop版本(21.0.0)

然后我无法隐藏ActionBar,其风格如下。

<style name="AppTheme.NoActionBar">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style>

我将其设置为特定活动。

<activity android:name=".NoActionBarActivity"
        android:theme="@style/AppTheme.NoActionBar"/>

当我使用appcompat-v7 20.0.0版本时,操作栏将按预期隐藏。

如何使用AppCompat版本21库隐藏自定义样式的操作栏?

2 个答案:

答案 0 :(得分:34)

@Chk0nDanger您的回答是正确的,但您应该使用以下代码:

<style name="Theme.AppCompat.NoActionBar" parent="Theme.AppCompat.Light">
   <item name="windowActionBar">false</item>
   <item name="android:windowNoTitle">true</item>
</style> 

没有父元素,一切都将是白色(textviewsbuttonschekcboxs等等!)

manifest.xml文件中:

    <activity android:name=".MyClass"
        android:theme="@style/Theme.AppCompat.NoActionBar"
        />

更新于2015年7月29日

升级到android:windowNoTitle

时,请确保windowNoTitle替换为AppCompat v22.1.0

答案 1 :(得分:10)

好的,我找到了答案。

appcompat-v7:21.0.0中有Theme.AppCompat.NoActionBar主题。 它定义如下。

<style name="Theme.AppCompat.NoActionBar">
   <item name="windowActionBar">false</item>
   <item name="android:windowNoTitle">true</item>
</style>

android属性中没有windowActionBar前缀。