處理回事件以這種方式
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch(id) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
在回壓法
@Override
public void onBackPressed() {
Intent intent = new Intent(SecondActivity.this,TabbedActivity.class);
intent.putExtra("IsBack",true);
startActivity(intent);
}
在選項卡式活動
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabs);
if(getIntent().getExtras().getBoolean("IsBack")){
//navigate to your desire fragment
}
}
作品完美,感謝 – Carasel