嗨,大家好,我嘗試在android工作室中實現一個後退按鈕,它將使我回到之前的活動。我設法在我的應用程序上顯示按鈕,但是當我按下按鈕時它不功能。我的程序中沒有錯誤。在Android工作室的後退按鈕
package com.example.window8.myfriend;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class design extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_design);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.images);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_image, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.home) {
Intent intent = new Intent(getApplicationContext(),Systemtime.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
可能有什麼原因,試着把一個日誌放在onOptionsItemSelected和if(id == R.id.home){},找出問題出在哪裏。 –