Android Question Exoplayer Controls Color

durdur

New Member
Licensed User
Does anyone know how to change the color of Exoplayer controls like play, pause, previous, next, duration, etc.?

Now, with the latest version, the controls stay in white color with blanck background, despite what I add into the manifest. I know how to change the background color with

Dim r As Reflector
r.Target = SimpleExoPlayerView1
Dim controller As B4XView = r.GetField("controller")
controller.GetView(0).Color = xui.Color_Green

I wish I can do the same with the controls, not only background. What will be the field name, if possible. For the background, thanks to Erel, it's "controller".

Thank you for your help.
 
Solution
Please use [code]code here...[/code] tags when posting code.

B4X:
Dim r As Reflector
	r.Target = SimpleExoPlayerView1
	Dim controller As B4XView = r.GetField("controller")
	controller.GetView(0).Color = xui.Color_Green
	For Each v As B4XView In controller.GetAllViewsRecursive
		If GetType(v) = "android.widget.ImageButton" Then
			SetColors(v, xui.Color_Red, xui.Color_Yellow)
		End If
	Next

Sub SetColors (v As B4XView, On As Int, Off As Int)
	Dim DrawableCompat As JavaObject
	DrawableCompat.InitializeStatic("android.support.v4.graphics.drawable.DrawableCompat")
	Dim drawable As JavaObject = DrawableCompat.RunMethod("wrap", Array(v.As(JavaObject).RunMethod("getDrawable", Null)))
	If drawable.IsInitialized = False Then
		Return
	End If...

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

B4X:
Dim r As Reflector
	r.Target = SimpleExoPlayerView1
	Dim controller As B4XView = r.GetField("controller")
	controller.GetView(0).Color = xui.Color_Green
	For Each v As B4XView In controller.GetAllViewsRecursive
		If GetType(v) = "android.widget.ImageButton" Then
			SetColors(v, xui.Color_Red, xui.Color_Yellow)
		End If
	Next

Sub SetColors (v As B4XView, On As Int, Off As Int)
	Dim DrawableCompat As JavaObject
	DrawableCompat.InitializeStatic("android.support.v4.graphics.drawable.DrawableCompat")
	Dim drawable As JavaObject = DrawableCompat.RunMethod("wrap", Array(v.As(JavaObject).RunMethod("getDrawable", Null)))
	If drawable.IsInitialized = False Then
		Return
	End If
	DrawableCompat.RunMethod("setTintList", Array(drawable.RunMethod("mutate", Null), CreateColorStateList(On, Off)))
	v.As(JavaObject).RunMethod("setImageDrawable", Array(drawable))
End Sub

'Based on: https://www.b4x.com/android/forum/threads/colorstatelist.40788/#content
Sub CreateColorStateList(On As Int,Off As Int) As Object
	Dim sd As StateListDrawable 'ignore
	Dim States(2,1) As Int
	States(0,0) = sd.State_Checked
	States(1,0) = sd.State_Enabled
	Dim CSL As JavaObject
	CSL.InitializeNewInstance("android.content.res.ColorStateList",Array(States, Array As Int(On, Off)))
	Return CSL
End Sub
 
Upvote 0
Solution

durdur

New Member
Licensed User
It works! I changed android.widget.ImageButton" by androidx.appcompat.widget.AppCompatImageButton.

Thank you so much!
 
Upvote 0
Top