Reputation: 95
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>
Upvotes: 4
Views: 1974
Reputation: 95
I found the solution by adding android:background="?attr/selectableItemBackground" insted of color hex
Link: Apply Material Design Touch Ripple to ImageButton?
Upvotes: 2
Reputation: 4374
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
Upvotes: 3