![](/img/trans.png)
[英]How to change the color of a button's icon when the button itself is being held in Android Studio?
[英]How to change the background color of a button when being held in Android Studio?
所以我在修改简单的代码时遇到了一些麻烦:我似乎无法让按钮的颜色在按住后发生变化,即使在使用颜色资源文件之后也是如此。 当我这样做时,它只会改变背景并且图标消失。
这是我的按钮代码:
<ImageButton
android:id="@+id/call_button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="248dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:background="#1072E1"
android:contentDescription="@string/call"
android:minWidth="48dp"
android:src="@android:drawable/stat_sys_phone_call"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@id/iv_image"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.466" />
那么有没有一种简单的方法可以改变它的背景颜色呢? 如您所见,背景颜色设置为#1072E1,但我想让它更动态并进行更改,以便当有人按住按钮时,颜色会发生变化并在释放后恢复正常(按钮的颜色可能是#0E63C4 , 例如)。
这很简单,但我遇到了麻烦。 如果有答案,我会提供更多细节。
您需要为按钮的按下状态设置不同的颜色,如this SO answer所示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.