简体   繁体   English

如何更改工具栏上的菜单图标大小?

[英]How to change menu icon size on toolbar?

This is my menu.xml file:这是我的 menu.xml 文件:

<?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/men_item_scan"
          android:title="@null"
          android:icon="@mipmap/scan_qr"
        app:showAsAction="always"/>
</menu>

and question is how can i change the size of the icon?问题是如何更改图标的大小? the scan_qr.png 's size is 224*89 but it's so small when the app is running on my phone. scan_qr.png的大小是224*89但是当应用程序在我的手机上运行时它太小了。

Use drawable instead改用 drawable

Try as fallow尝试休闲

<?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/men_item_scan"
          android:title="@null"
          android:icon="@drawable/scan_qr"
        app:showAsAction="always"/>
</menu>

drawable/scan_qr.xml change width and height drawable/scan_qr.xml更改宽度和高度

<vector android:height="24dp" android:width="24dp"
    android:tint="#FFFFFF"
    android:viewportHeight="24.0" android:viewportWidth="24.0"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#FF000000" android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
    <path android:fillColor="#FF000000" android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>

Finally, i used @ShivaSnape 's method, and it works for me.最后,我使用了 @ShivaSnape 的方法,它对我有用。

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:background="@color/colorPrimary">
    <ImageView
        android:id="@+id/img_qrorrfid"
        android:layout_gravity="end"
        android:layout_width="112dp"
        android:layout_height="44dp"
        android:scaleType="centerInside"
        android:src="@mipmap/scan_qr"/>
</android.support.v7.widget.Toolbar>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM