material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[Theming] On SDK <23 DrawerArrowDrawable incorrectly resolves color under ThemeOverlay.MaterialComponents.Toolbar.Surface

Open killvetrov opened this issue 6 years ago • 1 comments

Description: I noticed this issue by using Jetpack Navigation. NavigationUI.setupWithNavController(toolbar, navController) calls Toolbar.setNavigationIcon(new DrawerArrowDrawable()). This DrawerArrowDrawable sets its color by style attribute color. It works correctly in majority of cases on all API levels, but I encountered this issue when using Toolbar with @style/Widget.MaterialComponents.Toolbar.Surface, which sets color to @color/material_on_surface_emphasis_medium. For some reason when DrawerArrowDrawable gets this color on SDK <23, it resolves to red: 0.6 alpha is respected, but colorOnSurface is not.

Screenshot_1603540384

Expected behavior: DrawerArrowDrawable resolves color correctly (same as ?attr/homeAsUpIndicator) on all API levels.

Source code: Relevant code snippets below.

// from androidx.appcompat.graphics.drawable.DrawerArrowDrawable.java

final TypedArray a = context.getTheme().obtainStyledAttributes(null,
                R.styleable.DrawerArrowToggle, R.attr.drawerArrowStyle,
                R.style.Base_Widget_AppCompat_DrawerArrowToggle);
setColor(a.getColor(R.styleable.DrawerArrowToggle_color, 0));
<!-- from XML of AppCompat and Material Components -->

<style name="Widget.AppCompat.DrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle">
    <item name="color">?attr/colorControlNormal</item>
</style>

<style name="Widget.MaterialComponents.Toolbar.Surface">
    ...
    item name="android:theme">@style/ThemeOverlay.MaterialComponents.Toolbar.Surface</item>
</style>

<style name="ThemeOverlay.MaterialComponents.Toolbar.Surface" parent="">
    <item name="colorControlNormal">@color/material_on_surface_emphasis_medium</item>
    ...
</style>

<!-- material_on_surface_emphasis_medium.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:alpha="@dimen/material_emphasis_medium" android:color="?attr/colorOnSurface"/>
</selector>

Reproducing app: https://github.com/killvetrov/ToolbarIssue (APK included under /app)

Android API version: 22

Material Library version: 1.3.0-alpha03

Devices: physical Google Nexus 4 (latest update is API 22), emulator with API 22 image

killvetrov avatar Oct 24 '20 12:10 killvetrov

Duplicate of #1119

killvetrov avatar May 12 '21 11:05 killvetrov