Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+17 votes

How do you create a back button in the top left corner that allows you to go to the previous activity in android?

asked in CSC490_Spring2019 by (1 point)

2 Answers

+4 votes

Found an answer here at
https://stackoverflow.com/questions/14545139/android-back-button-in-the-title-bar

Need to add these methods

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
public boolean onCreateOptionsMenu(Menu menu) {
    return true;
}

And put this line in the oncreate method
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

answered by (1 point)
0 votes

I would think just drag the button to the top?

answered by (1 point)
...