创建图标按钮 - Android
Create icon button - Android
我想创建一个小图标按钮,正如所描述的那样 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 以使用图标?
您需要将该图标(假设它被命名为 my_button_image.png)下载到您的 drawable 目录并需要将 drawable 属性添加到您的按钮,
android:background="@drawable/my_button_image"
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 的内容。它已经有了选择器。
我想创建一个小图标按钮,正如所描述的那样 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 以使用图标?
您需要将该图标(假设它被命名为 my_button_image.png)下载到您的 drawable 目录并需要将 drawable 属性添加到您的按钮,
android:background="@drawable/my_button_image"
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 的内容。它已经有了选择器。