要在Android中使用ImageButton设置图片,可以按照以下步骤进行操作:
在XML布局文件中,将ImageButton添加到布局中。例如:<ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="https://www.jirixiang.com/static/image/lazy.gif" class="lazy" original="https://static.jirixiang.com/image/nopic320.png" />其中,@drawable/my_image表示要设置的图片资源,可以在res/drawable目录中添加图片资源文件。
ImageButton imageButton = findViewById(R.id.imageButton);imageButton.setImageResource(R.drawable.my_image);其中,R.drawable.my_image表示要设置的图片资源,可以使用setImageResource()方法设置图片。
注意:如果要为ImageButton设置不同的图片在不同的状态下(例如按下、禁用等),可以使用android:background属性来设置背景资源,并在Java代码中使用setBackgroundResource()方法设置不同状态下的背景资源。

