Set Duration of Long Key press Listener

前端 未结 3 2175
我在风中等你
我在风中等你 2021-01-23 11:33

Can we set duration for Long key press listener? What i want is, if user keeps touching the screen for 3 sec then my long key press listener should trigger and open my pop up fo

3条回答
  •  我在风中等你
    2021-01-23 11:58

    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);
    }
    

    Now to open the setting tab you can do following code inside and activity...

    Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    activityContext.startActivity(intent);
    

    For detail you can visit for better understanding.

提交回复
热议问题