在将我的应用程序从编译/定位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>
发布于 2017-07-27 08:13:31
问题是图标的大小比预期的要大。很明显,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
发布于 2017-10-11 16:18:21
我在appcompat-v7支持库的26.0.0版本中遇到了这个问题。更新到26.0.2已修正如下:)
发布于 2017-08-18 13:19:41
您需要生成不同的可绘制图标并将其放置在各自的文件夹中才能工作。您可以使用此链接生成不同大小的图标。
https://stackoverflow.com/questions/45340740
复制相似问题