문제

MediaController를 사용자 정의하는 방법이 있습니까? 버튼 스타일, Seekbar 등을 변경해야합니다.

도움이 되었습니까?

해결책

방법 makeControllerView 자신의 견해를 제공 할 수 있도록 무시해야했습니다. 불행히도 지금은 숨겨져 있습니다.

MediaController의 소스를 가져 와서 그것을 상환하거나 숨겨진 메소드를 서브 클래스로 복사하여 붙여 넣어 사용자 정의 할 수 있습니다.

다른 팁

당신이 할 수있는 일은 미디어 컨트롤러의 View Hierarchy를 되풀이하고 Seekbar의 추첨을 프로그래밍 방식으로 설정하는 것입니다.

private void styleMediaController(View view) {
    if (view instanceof MediaController) {
        MediaController v = (MediaController) view;
        for(int i = 0; i < v.getChildCount(); i++) {
            styleMediaController(v.getChildAt(i));
        }
    } else
        if (view instanceof LinearLayout) {
            LinearLayout ll = (LinearLayout) view;
            for(int i = 0; i < ll.getChildCount(); i++) {
                styleMediaController(ll.getChildAt(i));
            }
        } else if (view instanceof SeekBar) {
            ((SeekBar) view).setProgressDrawable(getResources().getDrawable(R.drawable.progressbar)); 
            ((SeekBar) view).setThumb(getResources().getDrawable(R.drawable.progresshandle));
        }
}

그런 다음 전화하십시오

styleMediaController(myMC);

BK138의 답변을 변경했습니다 색상을 변경합니다 요소의. 그 자체가 아닙니다. 이 솔루션은 지원 라이브러리 v4와 함께 오래된 장치와 호환됩니다.

private void styleMediaController(View view) {
        if (view instanceof MediaController) {
            MediaController v = (MediaController) view;
            for (int i = 0; i < v.getChildCount(); i++) {
                styleMediaController(v.getChildAt(i));
            }
        } else if (view instanceof LinearLayout) {
            LinearLayout ll = (LinearLayout) view;
            for (int i = 0; i < ll.getChildCount(); i++) {
                styleMediaController(ll.getChildAt(i));
            }
        } else if (view instanceof SeekBar) {
            ((SeekBar) view)
                    .getProgressDrawable()
                    .mutate()
                    .setColorFilter(
                            getResources().getColor(
                                    R.color.MediaPlayerMeterColor),
                            PorterDuff.Mode.SRC_IN);
            Drawable thumb = ((SeekBar) view).getThumb().mutate();
            if (thumb instanceof android.support.v4.graphics.drawable.DrawableWrapper) {
                //compat mode, requires support library v4
                ((android.support.v4.graphics.drawable.DrawableWrapper) thumb).setCompatTint(getResources()
                        .getColor(R.color.MediaPlayerThumbColor));
            } else {
                //lollipop devices
                thumb.setColorFilter(
                        getResources().getColor(R.color.MediaPlayerThumbColor),
                        PorterDuff.Mode.SRC_IN);
            }
        }
    }

그런 다음 전화하십시오

styleMediaController(myMC);

전화해야했습니다 styleMediaController(myMC) 에서 OnPreparedListenerVideoView 작동하게합니다. 그렇지 않으면 MediaController보기에는 자녀가 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top