2017-10-08 73 views
3

编辑:我刚刚意识到它实际上不是重音颜色。我尝试改变口音的颜色,并在其他地方改变时,我的导航项目的颜色保持粉红色。我只是认为这是重音的颜色,因为它与它相似。现在我不知道颜色来自哪里。导航抽屉项目是粉红色而不是黑色只在Android 8

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

在Android的7,他们仍然是黑色的,只有Android的8,这是不同的。另外,在Android Studio中查看设计预览时,它会将它们显示为API 26(Android 8)的黑色,但运行时它是重音颜色。

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

这就是它看起来像在Android Studio中的设计预览和8之前的版本: enter image description here

而在Android上8:

enter image description here

请注意,主要颜色仍然工作时,项目是活动的(这是我想要的),但如果我尝试改变图标的​​色调或te xt将其变为黑色时,它不再能够在活动时变为主要颜色,因此不能用作解决方法。

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> 

没有人有任何想法,为什么这可能发生?

+0

您可以添加style.xml和color.xml文件 –

+0

对不起,应该包括那些开头。现在包括。 – procinct

+0

看起来正确。你可以清理你的构建,卸载应用程序并运行它。 –

回答

3

好吧,我设法解决了它。事实证明,我使用的依赖关系为api level 23的主题,并且他们在Android 8中打破了。通过升级我的依赖项,目标SDK和编译SDK版本为26来解决此问题。

+0

千分感谢分享这些信息,我使用这个解决方案解决了我的问题,我使用Sublimenavigationview,它仅在Android Oreo中显示粉红色的项目。但在更新编译SDK到26和它解决的依赖项后。 – Mohtashim