【问题标题】:Nav drawer items are pink instead of black only in Android 8导航抽屉项目仅在 Android 8 中为粉红色而不是黑色
【发布时间】:2017-10-08 00:50:00
【问题描述】:

编辑:我刚刚意识到它实际上不是强调色。我尝试更改强调色,虽然它在其他任何地方都发生了变化,但我的导航项目的颜色仍然是粉红色。我只是假设它是强调色,因为它与它相似。现在我不知道那种颜色是从哪里来的。

我刚刚注意到,在我的应用中,导航抽屉项目是强调色,而不是在 Android 8 上运行时为黑色。

在 Android 7 中,它们仍然是黑色的,只有 Android 8 不同。此外,在 Android Studio 中查看设计预览时,API 26 (Android 8) 显示为黑色,但运行时显示为强调色。

以下是一些演示该问题的图片:

这是在 Android Studio 和 8 之前的版本中的设计预览中的样子:

在 Android 8 上:

请注意,当项目处于活动状态时,原色仍然有效(这是我想要的),但如果我尝试将图标或文本的色调更改为黑色,则它不再能够更改为原色处于活动状态,因此无法解决。

styles.xml

<resources>

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

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#F44336</color>
    <color name="colorPrimaryDark">#D32F2F</color>
    <color name="colorAccent">#FF4081</color>

</resources>

导航活动的xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main_nav"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main_nav"
        app:menu="@menu/activity_main_nav_drawer" />

</android.support.v4.widget.DrawerLayout>

有人知道为什么会发生这种情况吗?

【问题讨论】:

  • 你可以在这里添加你的style.xml和color.xml文件吗
  • 对不起,应该包括那些开始。现在包括在内。
  • 看起来正确。你能清理你的构建,卸载应用程序并运行它吗?
  • 不幸的是,在 Android 8 中仍然是粉红色的。我还将为导航活动添加我的 xml,以防出现问题。
  • 更改强调色后,粉红色项目保持粉红色,因此它显然不是来自强调色。我不知道这种颜色是从哪里来的。

标签: android android-layout


【解决方案1】:

好的,我设法解决了。原来我使用的是 API 级别为 23 的主题的依赖项,它们在 Android 8 中出现故障。通过升级我的依赖项、目标 SDK 并将 SDK 版本编译到 26 来解决问题。

【讨论】:

  • 感谢分享此信息,我使用此解决方案解决了我的问题,我使用的是仅在 Android Oreo 中显示粉红色项目的 Sublimenavigationview。但是在将 compile SDK 更新到 26 并解决了依赖项之后。
【解决方案2】:

找到解决方案 - 导航抽屉菜单项文本颜色粉红色问题在android 8.. 我也面临同样的问题发生在奥利奥(MiA1)。

*将编译SDK版本改为25。

compileSdkVersion 25

更新下面提到的那些库(app.gradle)

compile 'com.android.support:design:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:cardview-v7:25.3.0'
compile 'com.android.support:recyclerview-v7:25.3.0'
compile 'com.android.support:palette-v7:25.3.0'

【讨论】:

    【解决方案3】:

    对于任何使用更新的 sdk 版本来到这里的人:

    • 确保依赖项使用与编译 sdk 版本相同的版本

    这解决了我的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多