机器人图像按钮

如何创建一个没有文本和图像水平居中按钮? 我不想使用 ImageButton,因为我想定义一个不同的背景图像

177464 次浏览

You can just set the onClick of an ImageView and also set it to be clickable, Or set the drawableBottom property of a regular button.

    ImageView iv = (ImageView)findViewById(R.id.ImageView01);
iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub


}
});

You just use an ImageButton and make the background whatever you want and set the icon as the src.

<ImageButton
android:id="@+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/album_icon"
android:background="@drawable/round_button" />

enter image description here

just use a Button with android:drawableRight properties like this:

<Button android:id="@+id/btnNovaCompra" android:layout_width="wrap_content"
android:text="@string/btn_novaCompra"
android:gravity="center"
android:drawableRight="@drawable/shoppingcart"
android:layout_height="wrap_content"/>

You can use the button :

1 - make the text empty

2 - set the background for it

+3 - you can use the selector to more useful and nice button


About the imagebutton you can set the image source and the background the same picture and it must be (*.png) when you do it you can make any design for the button

and for more beauty button use the selector //just Google it ;)