首页 > 代码库 > Android 按键按下实现阴影效果

Android 按键按下实现阴影效果

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 (有白边的)

Android 按键按下实现阴影效果