Android 控件(View)之 TextView Button ImageButton ImageView CheckBox
2010-02-27 23:48:00 来源:WEB开发网3、ImageButton 的 Demo
imagebutton.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">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/textView" />
<!--
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("图片按钮被单击了");
}
});
}
}
更多精彩
赞助商链接