[英]How do I start an Activity with the HomeButton of the ActionBar
目前,我使用此代碼:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB){
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
,但現在Button不應該只是一個后功能。 我喜歡開始其他活動:
Intent intent = new Intent(CurrentActivity.this, MainActivity.class);
startActivity(intent);
我知道我應該使用setOnClickListener
,但是我不知道在哪里調用Listener。
盡管我同意Tanis.7x的評論,但如果不通過調用finish()
或popBackStack()
返回該按鈕,則不應使用該按鈕,
使用菜單選項調用主頁按鈕的操作
http://developer.android.com/guide/topics/ui/actionbar.html#Home
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked;
return true;
default:
return super.onOptionsItemSelected(item);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.