Android - change send icon's color on ImageButton
Asked Answered
D

7

14

How to change the default color of send icon on this ImageButton?

<ImageButton
    android:id="@+id/ImageButton1"
    android:layout_width="0dp"
    android:paddingTop="5dip"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:background="@null"
    android:gravity="right"
    android:scaleType="center"
    android:src="@android:drawable/ic_menu_send" />

enter image description here

I want to use gray instead of current white color.

Dieter answered 9/2, 2016 at 6:54 Comment(5)
Used ImageView and setColorFilter(GREY)Indoctrinate
@MD But I want to click on this button, So how to use clickable ImageView ?Dieter
@ why not? Check this POSTIndoctrinate
@afn see my answer bellow.Strategist
Please, use this class, is such more easy. github.com/jrvansuita/IconHandlerLanciform
C
43

Add tint attribute and you can set any color you want. Also you can set android:tintMode attribute (Which says how the color should apply).

 <ImageButton
        android:id="@+id/ImageButton1"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:gravity="right"
        android:paddingTop="5dip"
        android:scaleType="center"
        android:tint="@color/colorAccent"
        android:src="@android:drawable/ic_menu_send" />
Cariecaries answered 9/2, 2016 at 7:27 Comment(0)
G
8

You can use colorFilter on image view and can give any color runtime.

iv.setColorFilter(getResources().getColor(R.color.color_gray),
                PorterDuff.Mode.SRC_ATOP);
Gruelling answered 9/2, 2016 at 7:26 Comment(2)
what is PorterDuff.Mode.SRC_ATOP?Dieter
@afn it is mode of adding color to image or draw able. check here - developer.android.com/reference/android/graphics/…Gruelling
C
4

Add android:tint attribute to set the icon colour.

<ImageButton
    android:id="@+id/ImageButton1"
    android:layout_width="0dp"
    android:paddingTop="5dip"
    android:layout_weight="1"
    android:tint="@color/background_red"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:background="@null"
    android:gravity="right"
    android:scaleType="center"
    android:src="@android:drawable/ic_menu_send" />
Comprehend answered 9/2, 2016 at 7:4 Comment(1)
I have tried implementing this for a delete icon, but the red color is faded, am I missing something?Violist
C
2

enter image description here

put this image in your drawable folder and then

save it in drawable as an image

<ImageButton
        android:id="@+id/ImageButton1"
        android:layout_width="0dp"
        android:paddingTop="5dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@null"
        android:gravity="right"
        android:scaleType="center"
        android:src="@android:drawable/img" />
Cyclopropane answered 9/2, 2016 at 7:4 Comment(0)
P
2

You can use the below code to change it programmatically:

Drawable drawableTint = DrawableCompat.wrap(getResources()
        .getDrawable(imageResID)).mutate();
DrawableCompat.setTint(drawableTint, 
        ContextCompat.getColor(getContext(), R.color.colorTint));

yourImageButton.setImageDrawable(drawableTint);
Planetary answered 29/4, 2022 at 4:59 Comment(0)
S
1

download icon put inside drawable folder

Download Icon

<ImageButton
        android:id="@+id/ImageButton1"
        android:layout_width="0dp"
        android:paddingTop="5dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@null"
        android:gravity="right"
        android:scaleType="center"
        android:src="@drawable/downloded_icon_send" />
Strategist answered 9/2, 2016 at 7:5 Comment(0)
C
-2

you can put your costomize image in you drawable then you can use it as image src

Cyclopropane answered 9/2, 2016 at 6:56 Comment(1)
Edit the same answer instead of posting a new one!Vassell

© 2022 - 2024 — McMap. All rights reserved.