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" />
I want to use gray instead of current white color.
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" />
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);
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" />
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" />
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);
download icon put inside drawable folder
<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" />
你可以把你的costomize图像放在你的drawable中然后你可以将它用作图像src
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.