Toolbar menu items shrink after switching to library 26 support and AppBarActivity in AppCompatActivity

Yesterday I upgraded to new 26 support library and I also had to change the deprecated AppBarActivity to AppCompatActivity as it no longer exists.

I have the same problem as described in the link below, but "clean" or "rebuild" does not fix the problem. Why are the options menu items compressed if I'm using support library 26?

I have all my icons in hdpi and xhdpi. Some also in mdpi and ldpi ...

So why are my toolbar icons shrinking?

Here is the code I use in all my layouts that worked with all the previous support libraries (and I always use the most recent!):

   <android.support.design.widget.AppBarLayout
    android:id="@+id/myAppBar"
    android:layout_width="match_parent"


    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:minHeight="?attr/actionBarSize" />
</android.support.design.widget.AppBarLayout>

      

All my icons are defined as attr, so I can provide a light and dark version.

<item
        android:id="@+id/action_logbook"
        android:icon="?attr/icon_book"
        android:orderInCategory="100"
        android:title="@string/logbook"
        yourapp:showAsAction="ifRoom"/>

      

This is the attr in icons.xml

<attr name="icon_book" format="reference"/>

      

This is the style that the actual icon provides:

  <style name="MyBaseThemeLight" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="icon_book">@drawable/icon_book_white</item>
</style>

      

Here is a screenshot from support version 26.0.0: enter image description here

and this happens after the update: enter image description here

UPDATE: It works when I put the ImageView directly into the Toolbox:

 <android.support.design.widget.AppBarLayout
    android:id="@+id/myAppBar"
    style="@style/myAppBarStyle"
    android:layout_width="match_parent"

    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="?attr/bt_expenses" />


    </android.support.v7.widget.Toolbar>


</android.support.design.widget.AppBarLayout>

      

enter image description here

UDATE 2: Changing the code in version 26 of the ActionMenuItemView seems to be a problem to me, as it does not resize the icons to keep the width and high level:

See: public void setIcon(Drawable icon)

...

+3


source to share


3 answers


See this tray thread where I explain the bug: https://issuetracker.google.com/issues/64207386 . I also recompiled the library to fix this issue. Attached here: https://issuetracker.google.com/issues/64207386#comment19 .



EDIT: Problem fixed on 26.0.2

+1


source


The workaround seems to be using Image Asset Studio from Android Studio to create icon resources again. I hadn't used this tool before and put the icon image manually in different permission folders. it seems that com.android.support:appcompat-v7:26.0.0 changed the resolution of the image, my old hdpi icon was 72x72, the generated icon for hdpi is now 48x48.



+3


source


These two action bars are different. The minimum height is set from attributes, but both have a height value set to wrap_content .

The first bar consists of a second line with km, which increases the height of the application bar by wrapping both text images. The icons on the second are compressed because they probably have attributes set in wrap_content as well.

It would be better if you show both app bars that have the same design and comparison after switching to AppCompatActivity.

+1


source







All Articles