【发布时间】: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,以防出现问题。
-
更改强调色后,粉红色项目保持粉红色,因此它显然不是来自强调色。我不知道这种颜色是从哪里来的。