【问题标题】:Why the icon on the button looks so big?为什么按钮上的图标看起来那么大?
【发布时间】:2021-12-12 09:55:27
【问题描述】:

我试图给按钮一个图标,但它看起来像这样!

XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button.Icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test Button"
        app:icon="@drawable/ic_facebook"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

我试图在互联网上查找相关问题,但遗憾的是找不到与此问题相关的任何内容,或者我没有进行足够的搜索

【问题讨论】:

    标签: android material-design android-button material-components-android


    【解决方案1】:

    尝试将 app:iconSize="24dp" 属性添加到 xml 中的按钮。您可以更改 24dp 任何您想要的大小。值得一提的是,这仅适用于 MAterialButton。

    【讨论】:

    • 但是为什么在这个video 中没有设置app:iconSize 并且没有该属性的按钮看起来很好
    • 好吧,因为他正在使用系统矢量图像,并且可能他在 Android Studio 中选择了适当大小的图标,例如 18 或 24 dp。并且可能您使用的不是矢量,而是 png 或 jpeg 图像。如果您不喜欢使用 iconSize 属性,则可以将图像大小调整为适当的图标大小。
    猜你喜欢
    • 2012-12-07
    • 1970-01-01
    • 2015-09-25
    • 2013-06-09
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    相关资源
    最近更新 更多