Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change colour of text in android mediacontroller

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

like image 726
Will Avatar asked Dec 03 '22 01:12

Will


1 Answers

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.

like image 145
blobbie Avatar answered Dec 23 '22 08:12

blobbie