私は ActionBarSherlock ライブラリを使用しており、こことここで提案されている正確な手順に従って、前の画面へのナビゲーションを有効にしています。
私のコードは次のようになります。
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
と
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// This callback is used only when mSoloFragment == true (see
// onActivityCreated above)
switch (item.getItemId()) {
case android.R.id.home:
// App icon in Action Bar clicked; go up
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Reuse the
// existing
// instance
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
しかし、R.id.home が認識されず、ホームが赤く表示されます。:-/ ネイティブ アクションバーを使用すると、ホーム宣言によって ids.xml ファイルが表示されます。しかし、ここでは、ActionBarSherlock アクティビティを使用している間、宣言が見つかりません。何か不足していますか?