每当我为我的 ImageButton
设置 android:background
="colorxxx"时,按下 ImageButton
的效果就会丢失。
在添加该属性之前,它具有用深色填充图像的效果
我希望当 ImageButton
有 android:background
="colorxxx"
我的布局:
<?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>
最佳答案
涟漪效果是背景的一部分,比如android:background="?attr/selectableItemBackground"
,如果你自己设置了背景,涟漪就不会起作用了。
您可以改为按照 this other response 中所述更改按钮的色调
关于android - 我的 ImageButton 在添加背景颜色时失去了它的动画效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35236748/