Toggle thumb on user device volume button

Im using the search bar to control the volume of the device. I can change the volume of the device using the thumb of the search bar by simply dragging it onto the touchpad.

But when the user presses the volume (side) keys, I need to set the thumb position of the search bar accordingly.

Hw I can do it please let me know

thanks

+4
source share
1 answer

I got the solution by overriding the onkeydown event.

@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { int index = seekbar.getProgress(); seekbar.setProgress(index + 1); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { int index = seekbar.getProgress(); seekbar.setProgress(index - 1); return true; } return super.onKeyDown(keyCode, event); } 

Edited for more reference.

+7
source

Source: https://habr.com/ru/post/1315235/


All Articles