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"/>
How can I change my xml to have an icon instead ?
Add icons to the start, center, or end of this button using the app:icon , app:iconPadding , app:iconTint , app:iconTintMode and app:iconGravity attributes. If a start-aligned icon is added to this button, please use a style like one of the ". Icon" styles specified in the default MaterialButton styles.
An icon button is an icon that triggers some sort of action on the page. More accurately, technically speaking, an icon button is a button that contains an icon and no (visible) accompanying text. These buttons can be found in the majority of app and user interfaces today.
Add your adaptive icon to your app xml , create alternative drawable resources in your app for backward-compatibility with Android 8.0 (API level 26). You can then use the <adaptive-icon> element to define the foreground, background, and monochromatic layer drawables for your icons.
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>
Use this as your background for button
android:background="@drawable/drawable_bg"
And read this about RippleDrawable It has selectors already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With