-4

as title says, how to make my ripple effect on ImageButton (ripple effect assigned to this ImageButton) activated on backpressed() without back to the previous activity

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
meeftah
  • 95
  • 1
  • 1
  • 13

1 Answers1

1

with a bit of logic you could achieve that easily. what i thought of is that you have a method lets call it doSomething();

boolean onBackpressed = false;
private void doSomthing() {
    if(onBackpressed){
        finish();
    }else{
        // do anything else that the button wants to do;
    }
}

now onBackpressed() you could do this

@Override public void onBackpressed() {
    onBackpressed = true;
    myImageButton.performClick(); // myImageButton.callOnClick()
}

P.S: that i didn't call super.onBackpressed(); so we can control the back press without existing the app.

of course your imageButton click listener calls doSomething() method.

Kosh
  • 6,140
  • 3
  • 36
  • 67