完整内容请查看http://www.zhdoc.net/android/reference/android/widget/ImageButton.html

ImageButton

public class ImageButton
extendsImageView

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ android.widget.ImageButton
已知的直接子类 AppCompatImageButton, FloatingActionButton, ZoomButton


Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regularButton, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by thesetImageResource(int) method.
在按钮上显示图像(而不是文本),它可以被用户按下或点击。默认情况下,一个ImageButton看起来就像一个普通Button,标准按钮的背景在不同的按钮状态下,会改变颜色。按钮上的图片,由XML元素中android:src属性来定义,或由setImageResource(int)方法来设置。

To remove the standard button background image, define your own background image or set the background color to be transparent.
删除标准按钮上的背景图片,定义你自己的背景图片或者设置背景颜色为透明。

To indicate the different button states (focused, selected, etc.), you can define a different image for each state. E.g., a blue image by default, an orange one for when focused, and a yellow one for when pressed. An easy way to do this is with an XML drawable "selector." For example:
指明不同的按钮状态(focused,selected,等),你可以为每个状态定义不同的图片。例如,默认是一个蓝色的图片,当focused状态时,则为一个橙色的图片,而当pressed状态时,则为一个黄色的图片。一种简单的方法是使用一个XML drawable的selector”。例如:

<?xml version="1.0" encoding="utf-8"?>  xmlns:android="http://schemas.android.com/apk/res/android">  android:state_pressed="true" android:drawable="@drawable/button_pressed" />   android:state_focused="true" android:drawable="@drawable/button_focused" />   android:drawable="@drawable/button_normal" />  

Save the XML file in your project res/drawable/ folder and then reference it as a drawable for the source of your ImageButton (in theandroid:src attribute). Android will automatically change the image based on the state of the button and the corresponding images defined in the XML.
将XML文件保存到你的项目中的res/drawable/路径下,然后作为你的ImageButton的源的一个drawable来引用(在android:src属性中)。Android将根据按钮的状态和XML中定义的相应的图像,自动更改按钮的图像。

The order of the elements is important because they are evaluated in order. This is why the "normal" button image comes last, because it will only be applied afterandroid:state_pressed and android:state_focused have both evaluated false.
元素中的顺序非常重要,因为它们是按顺序进行计算的。这就是为什么“normal”的按钮图片是放置最后,因为它只会在android:state_pressedandroid:state_focused都被评估为false时,才会使用。

See the Buttons guide.
请参考Buttons。

XML attributes
XML属性

See Button Attributes,View Attributes
参考Button AttributesView Attributes

摘要


继承XML属性

From class android.widget.ImageView
From class android.view.View

继承常量

From class android.view.View

继承字段

From class android.view.View

Public构造方法

ImageButton(Context context)
ImageButton(Context context, AttributeSet attrs)
ImageButton(Context context, AttributeSet attrs, int defStyleAttr)
ImageButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public方法

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.
返回此对象的类名,用于辅助功能目的。

PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex)

Returns the pointer icon for the motion event, or null if it doesn't specify the icon.
返回MotionEvent的指针图标,如果没有指定图标,则为null。

保护方法

boolean onSetAlpha(int alpha)

Invoked if there is a Transform that involves alpha.
如果存在涉及alpha的转换, 则调用此方法。

继承方法

From class android.widget.ImageView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public构造方法


ImageButton

API level 1版本中可用
ImageButton (Context context)
参数
context Context

ImageButton

API level 1版本中可用
ImageButton (Context context, AttributeSet attrs)
参数
context Context
attrs AttributeSet

ImageButton

API level 1版本中可用
ImageButton (Context context, AttributeSet attrs, int defStyleAttr)
参数
context Context
attrs AttributeSet
defStyleAttr int

ImageButton

API level 21版本中可用
ImageButton (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
参数
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public方法


getAccessibilityClassName

API level 23版本中可用
CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.
返回此对象的类名,用于辅助功能目的。如果它们实现了一些在辅助服务中被视为视图的一个完全的新类,而与它所派生的类无关,则子类应该仅重载此方法。这个值在AccessibilityNodeInfo.setClassName中被填充。

返回
CharSequence  

onResolvePointerIcon

完整内容请查看http://www.zhdoc.net/android/reference/android/widget/ImageButton.html

更多相关文章

  1. Android 中三种使用线程的方法
  2. Android Button按钮两个页面切换
  3. android圆角按钮
  4. Android Activity onConfigurationChanged()方法 监听状态改变
  5. Android高手进阶教程(二十)之---Android与JavaScript方法相互调
  6. android中的坐标系以及获取坐标的方法
  7. Android与JavaScript方法相互调用
  8. 创建Android库的方法及Android .aar文件用法小结

随机推荐

  1. Android(安卓)6.0+ TelephonyManager 使
  2. 玩转android sqlLite---(附android DB的图
  3. Android(安卓)Material Design之TextInpu
  4. Android 上的 Scala, 实战之路(一)——先开
  5. 把ffmpeg-0.11.1整合到android项目中
  6. Android点击EditText之外的地方隐藏键盘
  7. Android(安卓)Audio System 之二:AudioFli
  8. Android的内存优化管理
  9. (Android design)新闻资讯类android客户
  10. android中的空指针异常NullpointExcepito