实际上,在这里使用着色做类似的事情。假设exoplayer布局xml文件包含以下内容
<ImageButton android:id="@id/exo_prev"
style="@style/ExoMediaButton.Previous"/>
<ImageButton android:id="@id/exo_rew"
style="@style/ExoMediaButton.Rewind"/>
<ImageButton android:id="@id/exo_play"
style="@style/ExoMediaButton.Play"/>
<ImageButton android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause"/>
<ImageButton android:id="@id/exo_ffwd"
style="@style/ExoMediaButton.FastForward"/>
val playButton = audioView.findViewById<ImageButton>(R.id.exo_play)
tintButton(playButton, color)
val pauseButton = audioView.findViewById<ImageButton>(R.id.exo_pause)
tintButton(pauseButton, color)
val prevButton = audioView.findViewById<ImageButton>(R.id.exo_prev)
tintButton(prevButton, color)
val rewindButton = audioView.findViewById<ImageButton>(R.id.exo_rew)
tintButton(rewindButton, color)
val ffwdButton = audioView.findViewById<ImageButton>(R.id.exo_ffwd)
tintButton(ffwdButton, color)
和
private fun tintButton(button: ImageButton, color: Int) {
val drawable = DrawableCompat.wrap(button.drawable)
DrawableCompat.setTintList(drawable.mutate(), ColorStateList.valueOf(color))
button.setImageDrawable(drawable)
}