【问题标题】:Create icon button - Android创建图标按钮 - Android
【发布时间】:2015-07-29 00:04:06
【问题描述】:

我想创建一个小图标按钮,正如 in this chapter of the material guideline 所描述的那样,但我找不到任何关于如何做到这一点的解释。

这是我要转换为图标切换的按钮:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_row="4"
    android:layout_column="0"
    android:id="@+id/btn_delete"
    android:drawableStart="@drawable/ic_delete"
    android:drawableLeft="@drawable/ic_delete"
    style="?android:attr/borderlessButtonStyle"/>

如何将我的 xml 更改为有一个图标?

【问题讨论】:

    标签: android button icons


    【解决方案1】:

    drawable_bg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Put your color for ripple effect -->
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@android:color/holo_green_dark">
        <item android:id="@android:id/mask">
            <shape android:shape="oval" >
            <!-- Color not displayed,just to tell ripple about the bounds -->
            <solid android:color="@android:color/black" />
            </shape>
        </item>
        <!-- And your drawable -->
        <item android:drawable="@drawable/btn_star_off_normal_holo_dark" />
    </ripple>
    

    将此作为按钮的背景

        android:background="@drawable/drawable_bg"
    

    阅读一下RippleDrawable,它已经有选择器了。

    【讨论】:

      【解决方案2】:

      你需要下载那个图标(假设它被命名为my_button_image.png)到你的drawable目录并且需要给你的按钮添加drawable属性,

      android:background="@drawable/my_button_image"
      

      【讨论】:

      • 是的,我已经有了我的图标图像,但是添加背景属性不会使我的按钮看起来像我想要的图标按钮。
      猜你喜欢
      • 2015-10-13
      • 2018-11-12
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多