【问题标题】:Squashed icons in toolbar after change to Android SDK 26更改为 Android SDK 26 后工具栏中的图标被压扁
【发布时间】:2017-07-27 03:16:49
【问题描述】:

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

下面是相关的布局代码:

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

这里是另一个会挤压的菜单(他们都这样做):

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

How it looks on SDK v25

How it looks on SDK v26

【问题讨论】:

标签: java android xml


【解决方案1】:

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

更新:

由于工具栏最小高度abc_action_bar_default_height_material56dpabc_action_bar_icon_vertical_padding_material16dp,因此工具栏图标在 mdpi 中的最小尺寸为 24dp

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

【讨论】:

  • 在 mdpi 上不应该是 24dp 吗?
  • 谢谢,你是对的,新的 SDK 在缩小图像时存在问题。使用正确大小的图像(从 24 像素开始)没有问题。
  • 实际上 mdpi 中的 32 px 在没有缩放错误的情况下也可以正常工作,但考虑到工具栏的最小高度,你是对的。所以我更新了答案。
【解决方案2】:

我在 appcompat-v7 支持库的 26.0.0 版本中遇到了这个问题。更新到 26.0.2 修复了它:)

请看这里:https://issuetracker.google.com/issues/64207386

【讨论】:

    【解决方案3】:

    您需要生成不同的可绘制图标并放置在相应的文件夹中才能工作。您可以使用this link 生成不同大小的图标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 2020-01-25
      • 2015-11-21
      • 1970-01-01
      相关资源
      最近更新 更多