Nav drawer elements are pink, not black only in Android 8

EDIT: I just realized that this is not really the color of the accent. I tried to change the color of the accent, and when it changed everywhere, the color of my navigational elements remained pink. I just assumed that it was the color of the accent because it was like him. Now I do not know where this color comes from.

I just noticed that in my application the elements of the navigation element are the color of the accent instead of being black when working on Android 8.

In Android 7 they are still black, but for Android 8 it is different. Also, looking at a preview of the design in Android Studio, it shows them as black for API 26 (Android 8), but when it starts it is the color of the accent.

Here are some images showing the problem:

This is what looks like a design preview in Android Studio and in versions prior to 8: enter image description here

And on Android 8:

enter image description here

Please note that the primary color still works when the element is active (as I want it), but if I try to change the hue of the icon or text to black, it will no longer be able to change the primary color if it does not work like that.

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 for navigation activity

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

Can anyone understand why this could happen?

+4
source share
1 answer

Well, I managed to figure it out. It turns out that I used dependencies for those with a level of 23 api, and they broke in Android 8. I managed to fix the problem by updating my dependencies, configure the SDK and compile the SDK version to version 26.

+4
source

Source: https://habr.com/ru/post/1687093/


All Articles