我正在尝试将事件分配给按钮,该按钮被声明为位图,我似乎无法弄清楚如何向其添加侦听器,甚至只是触摸按钮时可以调用的事件。
moregamesbtn = BitmapFactory.decodeResource(getResources(), R.drawable.moregames);
Bitmap moregamesbtn;
编辑 - 我尝试过这个,但没有成功;
moregamesbtn = BitmapFactory.decodeResource(getResources(), R.drawable.moregames);
ImageButton imgButton = (ImageButton) findViewById(R.drawable.moregames);
imgButton.setImageBitmap(moregamesbtn);
imgButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Log.e("MyApplication", "Pressing more games button");
}
});
您必须将位图分配给按钮背景
button.setBackgroundDrawable(bdrawable);
然后制作一个onButtonClick Listener。
编辑:您可能还想检查一下:http://www.mkyong.com/android/android-imagebutton-example/