java - 如何以编程方式替换/更改图像按钮android

标签 java android android-layout android-button

我的 View 上有一个图像按钮,我需要在用户交互后对其进行更改。我没有找到像 myImageButton.setDrawable 这样的东西 这是我要更改的按钮的 xml:

<ImageButton
        android:id="@+id/stopButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/buttons_background"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:background="@null"
        android:src="@drawable/btn_play" />

我需要以编程方式将 android:src="@drawable/btn_play" 更改为 android:src="@drawable/btn_stop" 的唯一一行。这可以做到吗?提前致谢。

最佳答案

你可以使用

setImageResource for the image button

关于java - 如何以编程方式替换/更改图像按钮android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16526112/

相关文章:

java - WSO2 Identity Server 5.10.0 和 Samples 4.2.0 继续出现 java.lang.ClassCastException : class org. opensaml.saml1.core.impl.ActionBuilder

java - 在 Java 中将 int 转换为 char

android,如何开始使用adsense

android - getItem() 在 FragmentPagerAdapter 中多次调用

java - Alertdialog.Builder 设置 View : Call requires API level 21

java - Android SQLite 表不存在

android - 适配器和充气机

android - 在 Android 中显示加速度计值

Android FrameLayout 不会被 Fragments 取代

android - ScrollView 不滚动的 RelativeLayout