开发者

Android listen for backbutton longclick

开发者 https://www.devze.com 2023-03-21 01:27 出处:网络
I am overriding the backbutton with a onBackPressed() function how开发者_JAVA技巧 do I also detect long clicks on the backbutton? Is there an equivalent of @Override onBackLongPressed() ?This might h

I am overriding the backbutton with a onBackPressed() function

how开发者_JAVA技巧 do I also detect long clicks on the backbutton? Is there an equivalent of @Override onBackLongPressed() ?


This might help you (Check the first comment) - Android long key press


From Android 2.0, Activity contains the method

public boolean onKeyLongPress(int keyCode, KeyEvent event)

For exemple, a long key press on the back button would be :

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) 
    {
        // do your stuff here
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}


Check "Story 2" here. There's not a shortcut for it like there is onBackPressed().


I think you'll have to use onKeyLongPress and handle the KEYCODE_BACK event yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消