将我的应用程序从编译/目标 SDK v25 更改为 SDK v26 后,我应用程序工具栏中的所有菜单图标现在都被压扁/压扁/拉伸(stretch)。
这里是相关的布局代码:
<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>
最佳答案
问题是图标尺寸比预期的要大。显然,缩放机制在 SDK 26 中发生了变化,现在它导致了这个 UI 错误。确保以下列尺寸提供工具栏图标资源。
更新:
由于工具栏最小高度 abc_action_bar_default_height_material
是 56dp
并且 abc_action_bar_icon_vertical_padding_material
是 16dp
,所以工具栏图标旨在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
关于java - 更改为 Android SDK 26 后工具栏中的图标被压扁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45340740/