Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+15 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.1k points)

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.1k points)
0 votes

I would think just drag the button to the top?

answered ago by (2.2k points)
...