Android中按钮有几种不同的状态,如何设置不同状态的图像按钮backgroundimage?

博主在尝试为Android应用程序的图像按钮设置两种状态:正常和触摸。他们已经在XML布局中使用了背景选择器(@drawable/homeselector等),但当点击按钮时,图像并未按预期切换到按下状态。博主尝试在onclick和ontouch事件中动态更改图像资源,但未成功。寻求解决方案,可能是通过使用选择器或者在运行时更改图像。
摘要由CSDN通过智能技术生成

如何设置不同状态的图像按钮backgroundimage?

我希望图像按钮有两种状态i)正常ii)触摸(或点击)。

我在图像按钮背景中设置了正常图像,我试图从onclick方法更改图像(按下),但它不会改变。

我希望如果我按下图像按钮,那么图像应该从正常变为按下,直到我按下其他按钮,但它不会发生。

任何人都可以向我建议如何使用选择器或在运行时这样做?

这是我的imagebuttonpanel代码。<?xml  version="1.0" encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal"

android:gravity="bottom"

android:id="@+id/buttonpanel">

android:layout_width="80dp"

android:layout_height="36dp"

android:focusable="true"

android:background="@drawable/homeselector">

android:layout_height="36dp"

android:layout_width="80dp"

android:background="@drawable/searchselector"

android:focusable="true">

>  

android:layout_height="36dp"

android:layout_width="80dp"

android:background="@drawable/registerselector"

android:focusable="true">

>  

android:layout_height="36dp"

android:layout_width="80dp"

android:background="@drawable/loginselector"

android:focusable="true">

我也尝试在ontouch和onclick事件上更改图像资源,但它没有帮助。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值