Icons look flat in action bar

Viewed 449

I've recently "upgraded" my android project to SDK version 26, and now the icons in my app bar look like this (run on Android 6.0), although the icon itself looks like this. I've got no idea why this is happening, I didn't change anything in the java or xml code that seems to be related to this. I would be very happy if someone posted a solution to this as this could be a bigger problem once Android 8 is released.

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'

    defaultConfig {
        applicationId "de.jamesbeans.quadrasolve"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "digit1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.android.support:percent:26.0.1'
}

relevant part of activity_main.xml:

<android.support.v7.widget.Toolbar
    android:id="@+id/maintoolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimaryDark"
    android:theme="@style/Widget.AppCompat.ActionBar"
    android:visibility="visible"
    app:popupTheme="@style/Theme.AppCompat.Light"
    app:title="QuadraSolve"
    app:titleTextColor="@android:color/background_light" />

relevant part of MainActivity.java:

Toolbar maintoolbar = (Toolbar) findViewById(R.id.maintoolbar);
setSupportActionBar(maintoolbar);

...

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.mainmenu, menu);
    return true;
}

mainmenu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_history"
        android:icon="@mipmap/ic_history_48px"
        android:title="@string/history"
        app:showAsAction="ifRoom">
    </item>
</menu>
1 Answers

Had the same issue and stumbled across this answer which seems to have fixed the problem:

https://stackoverflow.com/a/45344964/4579919

The matter is that the icon size is bigger then the expected. Obviously the scaling mechanism has changed in SDK 26 and now it leads to this UI bug. Make sure the toolbar icon resources are provided in the following sizes.

Related