Android控件(View)之TextView, Button, ImageButton, ImageView, CheckBox
2010-09-27 02:07:00 来源:WEB开发网< !--
ImageButton - 图片按钮控件
-->
< ImageButton android:id="@+id/imageButton"
android:layout_width="wrap_content" android:layout_height="wrap_content">
< /ImageButton>
< /LinearLayout>
_ImageButton.java
代码
package com.webabcd.view;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class _ImageButton extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.imagebutton);
setTitle("ImageButton");
ImageButton imgButton = (ImageButton) this.findViewById(R.id.imageButton);
// 设置图片按钮的背景
imgButton.setBackgroundResource(R.drawable.icon01);
// setOnClickListener() - 响应图片按钮的鼠标单击事件
imgButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
TextView txt = (TextView) _ImageButton.this.findViewById(R.id.textView);
txt.setText("图片按钮被单击了");
}
});
}
}
4、ImageView 的 Demo
imageview.xml
代码
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
< !--
ImageView - 图片显示控件
-->
< ImageView android:id="@+id/imageView"
更多精彩
赞助商链接