Android navigation/ toolbar back

Home  >>  Tutorials  >>  Android  >>  Android navigation/ toolbar back

Android navigation/ toolbar back

7
May,2018

0

Step one :

put these in oncreate method

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

 

 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

   
}

Step two :

Give action to go specific page or actions

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent(fromActivity.this, toActivity.class);
    startActivity(intent);
    return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    Intent intent = new Intent(fromActivity.this, toActivity.class);
    startActivity(intent);
}

Leave a Reply

Your email address will not be published. Required fields are marked *