Android Material Design- 即使在将 windowActionBar 设置为 false 并将 windowNoTitle 设置为 true 后,ActionBar 和 Title 仍可见

Android Material Design- ActionBar and Title visible even after setting windowActionBar as false and windowNoTitle as true

我正在试用 material 设计。我在样式中创建了一个主题MyMaterialTheme

样式:

<resources>
    <!-- Theme for the material design of the app -->
    <style name="MyMaterialTheme" parent="MyMaterialTheme.Base"></style>

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimaryApp</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDarkApp</item>
        <item name="colorAccent">@color/colorAccentApp</item>

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

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

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

在我的 AndroidManifest.xml 中,我包含了这个主题 (MyMaterialTheme)。我可以确认我的主题已应用,因为它从中获取了正确的颜色。我已将 windowActionBar 指定为 false,将 windowNoTitle 指定为 true,但当我 运行 应用程序时,我仍然看到 ActionBar 和标题。谁能指出我哪里出错了?

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/MyMaterialTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
           <!-- android:theme="@style/AppTheme.NoActionBar"> -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

模拟器截图如下:

检查您的 activity_main.xml 文件。 Android Studio 的默认布局通常会在每个布局中手动添加一个工具栏,即使您的应用主题说有 none。

你的 material 样式扩展它的基本样式应该是 noTitlebar 像这个代码

parent="Theme.AppCompat.Light.NoActionBar"