更改为Android SDK 26后,工具栏中的图标被压缩 [英] Squashed icons in toolbar after change to Android SDK 26

查看:172
本文介绍了更改为Android SDK 26后,工具栏中的图标被压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我的应用从编译/定位SDK v25更改为SDK v26后,我应用工具栏中的所有菜单图标现在都被压扁/压缩/拉伸。

After changing my app from compiling/targeting SDK v25 to SDK v26, all of the menu icons in my app's toolbar are now squashed/squished/stretched.

这里是相关的布局代码:

Here's the relevant layout code:

            <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    android:theme="@style/AppTheme.AppBarOverlay" />

                <br.com.mauker.materialsearchview.MaterialSearchView
                    android:id="@+id/search_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

            </RelativeLayout>

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

这是一个收集的菜单:

<?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_search"
    android:title="@string/search"
    android:icon="@drawable/ic_search_white_48dp"
    app:showAsAction="ifRoom" />

<item
    android:id="@+id/advanced_search"
    android:enabled="true"
    android:title="@string/advanced_search"
    app:showAsAction="never" />

</menu>

这是另一个菜单(他们都这样做):

Here's another menu that squishes (they all do):

<?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/add_photo"
    android:enabled="true"
    android:title="@string/add_photo"
    android:icon="@drawable/ic_add_a_photo_white_48dp"
    app:showAsAction="ifRoom" />

</menu>

它在SDK v25上的外观

它在SDK v26上的样子

推荐答案

问题在于图标大小比预期的要大。显然,SDK 26中的缩放机制已经改变,现在它导致了这个UI错误。确保以下列尺寸提供工具栏图标资源。

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.

已更新:

由于工具栏最小高度 abc_action_bar_default_height_material 56dp abc_action_bar_icon_vertical_padding_material 16dp ,工具栏图标的最小尺寸为 24dp ,mdpi:

Since the Toolbar min height abc_action_bar_default_height_material is 56dp and abc_action_bar_icon_vertical_padding_material is 16dp, the toolbar icons are meant to be with a min size of 24dp in mdpi:

drawable-mdpi - 24 x 24 px
drawable-hdpi - 36 x 36 px
drawable-xhdpi - 48 x 48 px
drawable-xxhdpi - 72 x 72 px
drawable-xxxhdpi - 96 x 96 px

这篇关于更改为Android SDK 26后,工具栏中的图标被压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆