java Android - 在 ImageButton 上更改发送图标的颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35285690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:56:43  来源:igfitidea点击:

Android - change send icon's color on ImageButton

javaandroidandroid-imagebutton

提问by Farzan Najipour

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

如何更改此发送图标的默认颜色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.

我想使用灰色而不是当前的白色。

回答by Tharindu Welagedara

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).

添加 tint 属性,您可以设置任何您想要的颜色。你也可以设置 android:tintMode 属性(它说明颜色应该如何应用)。

 <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" />

回答by Reaz Murshed

Add android:tintattribute to set the icon colour.

添加android:tint属性以设置图标颜色。

<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" />

回答by Wasim K. Memon

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

您可以在图像视图上使用 colorFilter 并可以提供任何颜色运行时。

iv.setColorFilter(getResources().getColor(R.color.color_gray),
                PorterDuff.Mode.SRC_ATOP);

回答by krishna

http://i.stack.imgur.com/F4L1Z.png

http://i.stack.imgur.com/F4L1Z.png

put this image in your drawable folder and then

将此图像放入可绘制文件夹中,然后

save it in drawable as an image

将其保存在 drawable 中作为图像

<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" />

回答by Suhas Bachewar

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" />

回答by krishna

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

你可以把你的costomize图像放在你的drawable中然后你可以将它用作图像src