Android UI设计 图片按钮ImageButton用法
图片按钮ImageButton可以把一张图片设为一个按钮,代替Button组件功能,以增加程序美感。
<?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"> <ImageButton android:id="@+id/ib" android:src="@drawable/bookmark_001" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
package com.pocketdigi; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageButton; public class main extends Activity { /** Called when the activity is first created. */ ImageButton ib; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ib=(ImageButton)findViewById(R.id.ib); ib.setOnClickListener(ibLis); }
private OnClickListener ibLis=new OnClickListener(){ @Override public void onClick(View v) {
// TODO Auto-generated method stub setTitle("图片按钮被点了");
}}; }