I want to add volume to action bar. When user clicks on that action it should place slider inside action bar for selecting right volume How would i do that
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
The easiest way to handle this is to use
ActionBar.setCustomView
.Here's an example that controls the media volume:
First, you'll need to create the custom layout that contains your
SeekBar
.Now implement
SeekBar.OnSeekBarChangeListener
in yourActivity
orFragment
and declare a couple of variables:In
onCreate
or wherever you choose to, inflate and apply the customView
to theActionBar
.To toggle the controls when your
MenuItem
is pressed, callActionBar.setDisplayShowCustomEnabled
and don't forget to update theSeekBar
progress to the current volume level you're controlling.To control the volume stream, in
OnSeekBarChangeListener.onProgressChanged
callAudioManager.setStreamVolume
And finally in
OnSeekBarChangeListener.onStopTrackingTouch
, remove the custom controls to display theActionBar
normally again.Here's a picture of before and after you press the
MenuItem
.Here is an answer of a similar question. He wanted to add Full audio Control buttons. You will find how to add the control
Seekbar
into youractionBar
and how to handle it.I hope it helps