seekbar thumb position change when user press device volume keys

后端 未结 1 1606
情书的邮戳
情书的邮戳 2021-01-19 21:28

Im using seek bar to control volume of the device. Im able to change the volume of the device using thumb of the seek bar just by dragging it on touch pad.

But when

相关标签:
1条回答
  • 2021-01-19 21:41

    I got solution, by overriding 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 further reference

    0 讨论(0)
提交回复
热议问题