android - 我的 ImageButton 在添加背景颜色时失去了它的动画效果

标签 android

每当我为我的 ImageButton 设置 android:background="colorxxx"时,按下 ImageButton 的效果就会丢失。

在添加该属性之前,它具有用深色填充图像的效果 我希望当 ImageButtonandroid: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/

相关文章:

Android 如何获取特定文件夹中可用的视频文件持续时间?

java - 以编程方式设置多个 ImageView 的 setImageResource() 会导致崩溃

Android Market 开发者控制台显示无错误报告

java - 无法在android中创建带有图像的文件夹

java - Activity 方向改变错误

java - 在android中只从字符串中获取数字

java - 在for循环之外打印数组java

android - 即使没有从 Manifest 中实例化,也要让小部件 BroadcastReceiver 保持 Activity 状态

android - 如何将现有的仅 header 源文件添加到 android studio?

android - Kotlin 图像压缩实现