-3

I hid the action bar in my app and added an "ImageView" that represents the back button, my question is how to hard coding the back button in android studio?

btnBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

0

you can call the back button function like this:

btnBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
              onBackPressed();
        }
    });

this will call onBackPressed() method of current activity's parent class.

jelic98
  • 723
  • 1
  • 12
  • 28
0

Just use finish() action in button clicklistener to back page.

btnBack.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
       finish();
    }
});
Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50