Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create icon button - 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"/>

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

like image 967
SocialSupaCrew Avatar asked Jul 29 '15 00:07

SocialSupaCrew


People also ask

How do I add an icon to a material button?

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.

Can an icon be a button?

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.

How do I make adaptive icons on android?

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.


1 Answers

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.

like image 156
Dhinakaran Thennarasu Avatar answered Nov 14 '22 23:11

Dhinakaran Thennarasu