Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

my ImageButton lose it's animation effect on adding background color

Tags:

android

whenever i set android:background="colorxxx" for my ImageButton, the effect of pressing ImageButton will lost.

before adding that attribute it has an effect filling the image with dark color i want it works too when ImageButton has android:background="colorxxx"

my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:context=".HomeActivity">

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:background="@color/ColorPrimary"
    android:layout_height="?attr/actionBarSize">

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/ColorPrimary"
        android:src="@drawable/a"
        android:layout_weight="50"
        android:adjustViewBounds="true" />

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/ColorPrimary"
        android:src="@drawable/b"
        android:layout_weight="50"
        android:adjustViewBounds="true" />

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/ColorPrimary"
        android:src="@drawable/c"
        android:layout_weight="50"
        android:adjustViewBounds="true" />

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/ColorPrimary"
        android:src="@drawable/d"
        android:layout_weight="50"
        android:adjustViewBounds="true" />
</LinearLayout>

like image 941
Kamran Borbor Avatar asked Oct 17 '25 17:10

Kamran Borbor


1 Answers

The ripple effect is part of the background, like android:background="?attr/selectableItemBackground", if you set a background yourself, the ripple will no longer work.

You can instead change the tint of your button as stated in this other response

like image 58
Logain Avatar answered Oct 19 '25 08:10

Logain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!