编辑:我刚刚意识到它实际上不是强调色。我尝试更改强调色,虽然它在其他地方都发生了变化,但我的导航项的颜色仍然是粉红色。我只是假设它是强调色,因为它与它相似。现在我不知道那种颜色是从哪里来的。
我刚刚注意到,在我的应用程序中,抽屉导航项目在 Android 8 上运行时是强调色而不是黑色。
在 Android 7 中它们仍然是黑色的,只是 Android 8 有所不同。此外,在 Android Studio 中查看设计预览时,对于 API 26 (Android 8),它们显示为黑色,但在运行时显示为强调色。
这里有几张图片展示了这个问题:
这是 Android Studio 和 8 之前版本的设计预览中的样子:
在 Android 8 上:
请注意,当项目处于 Activity 状态时(这是我想要的),原色仍然有效,但是如果我尝试将图标或文本的色调更改为黑色,则当活跃所以这不能作为解决方法。
样式.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>
颜色.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>
导航 Activity 的 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>
有谁知道为什么会发生这种情况?
最佳答案
好的,我设法解决了。原来我使用的是 api 级别 23 的主题依赖项,它们在 Android 8 中被破坏了。通过升级我的依赖项、目标 SDK 并将 SDK 版本编译到 26 设法解决了这个问题。
关于android - 抽屉导航项目仅在 Android 8 中为粉红色而非黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46626537/