4

Hi is there a way of changing the colour of the text in a mediacontroller showing the total time and remaining time of an audio file. On android 2.3 the times are clearly visible but when my app is run on android 4.0 or 4.1 the text showing the times either side of the progress bar are too dark. Currently I am extending the mediacontroller class to create my own media controller that does not dissapear, is there something I could add to this class perhaps? Any help would be much appreciated.

public class WillMediaController extends MediaController {

    public WillMediaController(Context context) {
        super(context);
    }

    @Override
    public void hide() {
        // Do Nothing to show the controller all times

    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event)
    {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
        {
            ((Activity) getContext()).finish();

        }else{
            super.dispatchKeyEvent(event);
        }
        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN ||
                event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
            // don't show the controls for volume adjustment
            return super.dispatchKeyEvent(event);
        }
        return true;


    }
}

Thanks

Will
  • 1,487
  • 1
  • 23
  • 35

2 Answers2

13

I had the same problem. A good way to go is to change the color using a theme. Use a ContextThemeWrapper to apply a theme to your MediaController, e.g.:

private final class AudioMediaController extends MediaController {

    private AudioMediaController(Context context) {
        super(new ContextThemeWrapper(context, R.style.Theme_MusicPlayer));
    }
}

Your theme could look like this:

<resources>
    <style name="Theme_MusicPlayer">
        <item name="android:textColor">#FFFFFF</item>
    </style>
</resources>

save it as an XML-file to your res/values folder. The color of every text in the media controller (current time & end time) is now white.

林果皞
  • 7,539
  • 3
  • 55
  • 70
blobbie
  • 1,279
  • 1
  • 10
  • 8
  • Fantastic Answer, how does one change the color of the Progress Bar - it appears as ugly Bright Yellow by default! – Jasper Jan 05 '15 at 05:22
4

It's kind of difficult actually. If you take a look at the source code of MediaController, you will notice that the views it used have an internal id (for instance com.android.internal.R.id.time) which you cannot access easily.

Though, you could try to use reflection to get the views instances and then modify their attributes. For instance, you can try to get a reference to the mEndTime field and then change its text color. e.g:

try {
    Field currentTime = getClass().getDeclaredField("mCurrentTime");
    currentTime.setAccessible(true);
    TextView currentTimeTextView = (TextView) currentTime.get(this);
    currentTimeTextView.setTextColor(Color.RED);
} catch (Exception pokemon) {
}
Cristian
  • 198,401
  • 62
  • 356
  • 264