Android seekbar (custom) controls volume synchronization updates
Android seekbar control volume synchronization update
As a developer, you will encounter seekbar, so how to customize seekbar and how to update the volume controlled by seekbar synchronously with the seekbar volume of the system. Today, take seekbar volume control in the drop-down menu as an example (Android 5.1 system)
1: Custom seekbar
Let's take a look at the customized renderings:
First, let's look at the layout file:
You need to take a look at Android: progressdrawable = "@ drawable / zf_progress_horizontal"_ progress_ What's in the horizontal.xml file.
There are two pictures here. The following figure shows the effects of these two pictures @ drawable / progress_ Blue and @ drawable / progress_ gray
About thumb = "@ drawable / zf_noti_scraper_control_normal" this is the picture of the pressed button
Well, that's all the layout code. The rest is the code to control the volume.
2: Synchronous update with system seekbar volume
1. First take a look at the code to control the volume
Open the code under the following path
Frameworks / base / packages / systemui / SRC / COM / Android / systemui / statusbar / phone / phonestatusbar. Java registers the ID in the protected phonestatusbarview makestatusbarview() {} method, and then implements the control code in it.
Looking at the code, we can find that when seekbar changes, what I deal with here is that the system volume and media volume change at the same time.
AudioManager.STREAM_ System and audiomanager.stream_ MUSIC。 You can also use the media volume to monitor changes in monitoring status. The effect is the same.
2. Synchronous update with system seekbar control volume
It mainly monitors the volume change broadcast. Let's take a look at the implementation code:
The myregisterreceiver () method has been registered in the code in 1. In this way, the whole function will be realized. In this process, I feel that the implementation of the function is very simple. The key is that the seekbar progress bar should be updated in real time with the volume progress bar of the system. This is the key. The above is all the control codes.
Thank you for reading. I hope I can help you. Thank you for your support to this site!