代码如下
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;
public class MainActivity extends Activity {
private ImageButton Ibtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Ibtn = (ImageButton)findViewById(R.id.imageBtn);
Ibtn.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN){
Ibtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.press));
}
else if(event.getAction() == MotionEvent.ACTION_UP){
Ibtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.nopress));
}
return false;
}
});
}
}
其中setBackgroundDrawable函数中间打了一条横线,不能被用,为什么?
------解决方案--------------------
看异常的詳細日志啊