Android为返回键设置动画效果

开始把问题想的很傻很天真

public boolean onKeyDown(int keyCode, KeyEvent event) {
	// TODO Auto-generated method stub
	if(keyCode == KeyEvent.KEYCODE_BACK) {
		overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
	}
	return super.onKeyDown(keyCode, event);
}
结果不成功。

换个思路,从生命周期来考虑,把动画放到onPause()里面就搞定了。

protected void onPause() {
	// TODO Auto-generated method stub
	super.onPause();
	overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}



你可能感兴趣的:(android)