0

ここで、2番目のavticityのoncreateメソッドでこれをセットアップします

        super.onCreate(savedInstanceState);
//        Actionbar
        getActionBar().setDisplayHomeAsUpEnabled(true);
        setContentView(R.layout.new_message);

そして、これはonOptionsItemSelectedです

   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();        
        if (id == R.id.action_save) {
            Intent newMessage = new Intent(getApplicationContext(),NewMessage.class);
            startActivity(newMessage);

        }
        if(id == R.id.home){
            Toast.makeText(getApplicationContext(), "Home button click", 2000).show();
            Intent intent = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(intent);
        }
/*        return super.onOptionsItemSelected(item);*/
        return true;
    }

マニフェストなどの他の場所を変更する必要があるものはありますか? MainActivity に戻るアクティビティのコードはありません

4

1 に答える 1

1

問題:

if(id == R.id.home)

プロジェクトの R Java の ID を使用していますが、これは間違いなく false を返します。これは、R が生成したホームの ID ではなく、ネイティブの Android ホームであると想定されています。

解決:

if(id == android.R.id.home)
于 2014-08-03T07:45:16.090 に答える