implement back button in Android studio | back button in action bar || Androidpro App Builders Androidpro.in

In this post we will read to how to add/set back button in android app projects in action bar in android studio.

Here provide a android studio code which code we use in activity of android studio projects, paste this code where you want to show the back button for go back after clicked, for example we create a story app and we want to  show back button in details story page then we need to paste this java code in the details story activity in java file in the main section. For more explain I suggest to you watch video which below here.

Step 1 Create a project

Step 2 Create new activity (for go next page)

Step 3 paste code in the second activity (new activity) which below

Java Code

ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {

        actionBar.setDisplayHomeAsUpEnabled(true);

   }

}

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;

 

 

Post a Comment

0 Comments