ImageButton
类结构图:
ImageButton就是用一个图标代表了一些文字,它没Android:text属性。它由Android:src指定图标的位置
android:src="@drawable/back_48"
其他属性都和Button差不多
实践演练:
1、 怎么样设置ImageButton的图标位置
- <ImageButton android:id="@+id/imgBtn01" android:src="@drawable/forward_48"
- android:layout_width="wrap_content" android:layout_height="wrap_content" />
2、 怎么样为ImageButton添加监听器注册事件
与Button一样它照样有两种方式设置
方式1:通过onClickListener
- imgBtn01.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- myTextView.setText("ImageButton的监听事件");
- }
- });
方式2:通过XML文件设置
- <ImageButton android:id="@+id/imgBtn02" android:src="@drawable/back_48"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:onClick="ImageButtonXml" />
最终效果:
1、 设置透明度
imgBtn01.setAlpha(50);//设置透明度