【问题标题】:Android Material Design- ActionBar and Title visible even after setting windowActionBar as false and windowNoTitle as trueAndroid Material Design-即使将 windowActionBar 设置为 false 并将 windowNoTitle 设置为 true 后,ActionBar 和 Title 仍然可见
【发布时间】:2016-01-17 18:07:55
【问题描述】:

我正在尝试材料设计。我在样式中创建了一个主题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>

这是模拟器的截图:

【问题讨论】:

  • 这些代码在您的样式中重复:&lt;item name="windowNoTitle"&gt;true&lt;/item&gt; &lt;item name="windowActionBar"&gt;false&lt;/item&gt;
  • @LinX64 感谢您的评论。您是指 AppTheme.NoActionBar 中的项目?
  • 这就像 android studio 的默认示例,这个:&lt;style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar" 我认为你应该删除它们。顺便说一句,我试过这个:android:windowNoTitle,但没有用.除非,您必须使用 java 之类的:requestWindowFeature(Window.FEATURE_NO_TITLE);
  • 你能显示你的布局xml代码吗? Android Studio 的默认布局通常会在每个布局中手动添加一个工具栏,即使您的应用主题显示没有
  • @TheoKanning 非常感谢。你说的对。刚刚看到我的activity_main.xml,它有一个工具栏,默认情况下,mainActivity.java 已经设置了它。删除后就没了。

标签: android material-design android-styles


【解决方案1】:

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

【讨论】:

  • 非常感谢。你说的对。它包含在 activity_main.xml 中。
【解决方案2】:

你的材料风格扩展它的基本风格应该是 noTitlebar 这样的代码

parent="Theme.AppCompat.Light.NoActionBar"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 2020-11-25
    相关资源
    最近更新 更多