创建图标按钮 - Android [英] Create icon button - Android

查看:154
本文介绍了创建图标按钮 - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个小图标按钮,如描述在材料指南的这一章中,但我找不到有关如何做到这一点的任何解释。

I want to create a small icon button as it is described in this chapter of the material guideline, but I can't find any explanation on how to do that.

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

Here is the button I want to transform to an icon toggle:

<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而不是图标?

How can I change my xml to have an icon instead ?

推荐答案

drawable_bg.xml

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 它已经有选择器。

And read this about RippleDrawable It has selectors already.

这篇关于创建图标按钮 - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆