【问题标题】:How to get material icon button in Android?如何在Android中获取材质图标按钮?
【发布时间】:2019-07-28 03:04:49
【问题描述】:

如何在 android 中获取材质按钮?我试过这段代码,但不知道如何包含这样的图像:

<com.google.android.material.button.MaterialButton
    android:id="@+id/material_button"
    style="@style/Widget.MaterialComponents.Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add to Cart"/>

【问题讨论】:

  • Android Studio 上New &gt; Vector Assets 下有免费图标。将它们设置为Button 中的android:drawableLeft,您也将获得类似示例的效果。

标签: android material-design android-button


【解决方案1】:

对于Material Button,使用iconiconGravity 属性,如下所示:

<com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button.Icon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Icon Button"
        app:icon="@drawable/your_icon"
        app:iconGravity="textStart"/>

阅读文档以更好地理解:Here

【讨论】:

  • 注意namespace 应该是 app 而不是 android
猜你喜欢
  • 2019-10-13
  • 2020-02-06
  • 2022-01-11
  • 2021-03-04
  • 1970-01-01
  • 1970-01-01
  • 2020-09-13
  • 2020-09-12
  • 2019-03-23
相关资源
最近更新 更多