要设置Android图像按钮ImageButton,可以按照以下步骤进行操作:
<ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/my_image" android:background="@android:color/transparent" /> 在上述代码中,使用android:src属性指定图像按钮的图像资源,使用android:background属性设置按钮背景为透明。
ImageButton imageButton = findViewById(R.id.imageButton); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 处理点击事件 } }); imageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageButton.setBackgroundResource(R.drawable.my_button_bg); 在上述代码中,通过setOnClickListener()方法设置按钮的点击事件监听器,setScaleType()方法设置图像按钮的缩放类型,setBackgroundResource()方法设置按钮的背景。
希望以上步骤对您有所帮助!