代码之家  ›  专栏  ›  技术社区  ›  Sasha Shpota A-Bag

ExoPlayer:如何更改控制器元素的颜色

  •  0
  • Sasha Shpota A-Bag  · 技术社区  · 6 年前

    我有一个自定义控件,通过 exo_player_control_view.xml 文件我需要的唯一区别是元素的不同颜色(按钮和时间线)。

    但事实证明,我需要复制粘贴所有图标的XML仅更改颜色属性。这当然是可行的,但我希望有一个简单的方法。

    另一个问题是图标在Apache 2.0许可下( example )我不确定是否允许将它们复制到我的项目中。

    如何更改控制器元素的颜色?是否可以在不复制和修改标准图标的情况下执行此操作?

    2 回复  |  直到 6 年前
        1
  •  1
  •   John O'Reilly    6 年前

    实际上,在这里使用着色做类似的事情。假设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)
    }
    
        2
  •  1
  •   Rohan buddy    6 年前

    ImageButton play = findViewById(R.id.exo_play);
    Drawable drawable = play.getDrawable();
    drawable.setTintList(ColorStateList.valueOf(Color.parseColor("#41a8ff")));