what is use of image button?

老子叫甜甜 提交于 2019-12-13 02:13:23

问题


I'm new to Android application development. I would like to ask the use of image button in Android programming when simple button can also add the image with the button. How can we generate click event of image button?


回答1:


If you will look in the API for Button you will see that it has a method called setOnClickListener that is inherited from View. Since ImageButton is also a view, you can also call the same method for it.

The only way that I see to use an image in a Button is by using android:background in the XML. This is only used for setting what's shown behind the text of a button. You should use ImageButton when you want to make a button that only uses the image as its defining feature. If you end up wanting to only see the image and have no part of the button background visible, you can set android:background on the button to use an invisible Drawable.




回答2:



The Image Button control is a special type of button that displays a Drawable graphic instead of text.

The Image Button and Button controls are both derived from the View class, but they are unrelated to each other. The Button class is actually a direct subclass of Text View (think of it as a line of text with a background graphic that looks like a button), whereas the Image Button class is a direct subclass of Image View.



来源:https://stackoverflow.com/questions/4203650/what-is-use-of-image-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!