Change style of android MediaController

前端 未结 3 1245
囚心锁ツ
囚心锁ツ 2020-12-09 06:01

Is there a way to customize the MediaController? I need to change the style of buttons, SeekBar etc.

3条回答
  •  轮回少年
    2020-12-09 06:57

    What you can do is recurse the view hierarchy of your MediaController and set the SeekBar's drawable programmatically:

    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));
            }
    }
    

    Then, just call

    styleMediaController(myMC);
    

提交回复
热议问题