Android 安卓图像按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2283444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android image button
提问by Arutha
How can i create a button with no text and an image centered horizontally ? I don't want to use an ImageButton because I want to define a different backgound image
如何创建一个没有文本的按钮和一个水平居中的图像?我不想使用 ImageButton 因为我想定义不同的背景图像
回答by CaseyB
You just use an ImageButton and make the background whatever you want and set the icon as the src.
您只需使用 ImageButton 并根据需要制作背景并将图标设置为 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" />
回答by user2347796
just use a Button with android:drawableRight properties like this:
只需使用具有 android:drawableRight 属性的按钮,如下所示:
<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"/>
回答by Patrick Kafka
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 的 onClick 并将其设置为可点击,或者设置常规按钮的 drawableBottom 属性。
ImageView iv = (ImageView)findViewById(R.id.ImageView01);
iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
回答by Oubaida AlQuraan
You can use the button :
您可以使用按钮:
1 - make the text empty
1 - 使文本为空
2 - set the background for it
2 - 为其设置背景
+3 - you can use the selector to more useful and nice button
+3 - 您可以使用选择器来获得更有用和漂亮的按钮
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
关于图像按钮,您可以将图像源和背景设置为相同的图片,并且必须是(*.png),当您这样做时,您可以为按钮进行任何设计
and for more beauty button use the selector //just Google it ;)
和更多的美容按钮使用选择器//只是谷歌它;)