首页 > 技术文章 > Android 按键按下实现阴影效果

code666 2017-06-08 21:23 原文

final Button btn_gallery=(Button)findViewById(R.id.btn_gallery);
btn_gallery.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intentgallery=new Intent(Intent.ACTION_GET_CONTENT);
intentgallery.setType("image/*") ;
startActivityForResult(intentgallery,GALLERY_REQUEST_CODE);
}
});
btn_gallery.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int action = motionEvent.getAction();
switch (action){
case MotionEvent.ACTION_DOWN:
btn_gallery.setBackgroundResource(R.drawable.galleryyy);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
btn_gallery.setBackgroundResource(R.drawable.galleryy);
break;
}

return false;
}
});


galleryyy 


galleryy (有白边的)

推荐阅读