简体   繁体   中英

Android Physical Keyboard Feedback (Keyclicks)

The soft pop up keyboard makes a sound when a key is pressed. I would play a sound when a key is pressed on the physical keyboard that we have built into our android hardware. Any advice of how I can do this.

You can use View.OnKeyListener . It will be invoked only for the Hardware keyboard. Just set it up like this:

    editText.setOnKeyListener((v, keyCode, event) -> {
        editText.playSoundEffect(SoundEffectConstants.CLICK); // Or play sound in any other way
        return false;
    });

Pay attention to return false . Otherwise your input won't be passed to the view because by returning true you are saying to the framework that your listener handled input already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM