Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - change send icon's color on ImageButton

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.

like image 363
Farzan Najipour Avatar asked Feb 09 '16 06:02

Farzan Najipour


2 Answers

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);
like image 70
Wasim K. Memon Avatar answered Oct 25 '22 11:10

Wasim K. Memon


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" />
like image 29
Tharindu Welagedara Avatar answered Oct 25 '22 12:10

Tharindu Welagedara