一:用图片做按钮背景。
用图片做钮背景一般有两种方法,都是把图片资源放在/res/drawable中,可以新建一个drawable文件,也可以直接把图片放在drawable-hdpi文件夹中。一种是在布局文件中引用到资源,一种是在java文件中引用到资烦的。
1:在界局文件中引用的。
main.xml中设置如下:
<ImageButton
android:id="@+id/bn2"
android:layout_width="60dp"
android:layout_height="60dp"
android:text="bn2"
android:background="@drawable/c2"
/>
引用到的图片c2要事先拉到/res/drawable里面:
java文件中,只要到对应的Button都改为ImageButton即可:
private ImageButton bn1;
private ImageButton bn2;
private ImageButton bn3;
private TextView t1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bn1=(ImageButton)findViewById(R.id.bn1);
bn2=(ImageButton)findViewById(R.id.bn2);
bn2=(ImageButton)findViewById(R.id.bn3);
t1=(TextView)findViewById(R.id.t1);
三面三个圆形图片即是。(为了效果好一点,一般把图片背景设为透明的,保存为PNG格式)
