1.工程目录
a.在res目录-新建drawble文件夹放入自定义图片
2.main.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:text="@string/hello"
/>
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:src="@drawable/sy"
/>
</LinearLayout>
3.类代码
package com.YANSE;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageButton;
public class YANSE extends Activity {
private ImageButton Image =null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Image=(ImageButton)findViewById(R.id.button);
}
}