修改android videoView 自带的控制条样式

修改android videoView 自带的控制条样式

自定义MediaController ,反射遍历找到 seekBar,设置seekBar样式

public class MyMediaController extends MediaController {
public MyMediaController(Context context, AttributeSet attrs) {
super(context, attrs);
}

public MyMediaController(Context context, boolean useFastForward) {
    super(context, useFastForward);
}

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



@Override
public void setAnchorView(View view) {
    super.setAnchorView(view);

    try {

        Field mRoot = android.widget.MediaController.class
                .getDeclaredField("mRoot");
        mRoot.setAccessible(true);
        ViewGroup mRootVg = (ViewGroup) mRoot.get(this);
        ViewGroup vg = findSeekBarParent(mRootVg);
        int index = 1;
        SeekBar sb=null;
       for (int i = 0; i < vg.getChildCount(); i++) {
            if (vg.getChildAt(i) instanceof SeekBar) {
                index = i;
                sb =(SeekBar)vg.getChildAt(i);
                break;
            }
        }
     if(null != sb) {
         decorateSeekbar(sb);
     }


    } catch (NoSuchFieldException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private ViewGroup findSeekBarParent(ViewGroup vg) {
    ViewGroup viewGroup = null;
    for (int i = 0; i < vg.getChildCount(); i++) {
        View view = vg.getChildAt(i);
        if (view instanceof SeekBar) {
            viewGroup = (ViewGroup) view.getParent();
            break;
        } else if (view instanceof ViewGroup) {
            viewGroup = findSeekBarParent((ViewGroup) view);
        } else {
            continue;
        }
    }
    return viewGroup;

}

private void decorateSeekbar(SeekBar seekBar) {
    seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.seekbar_style));
    seekBar.setThumb(getResources().getDrawable(R.drawable.review_slider));

    seekBar.setPadding(0,Util.dip2px(this.getContext(),13),0,Util.dip2px(this.getContext(),13));
    try {
        Class<?> superclass = seekBar.getClass().getSuperclass().getSuperclass();
        Field mMaxHeight = superclass.getDeclaredField("mMaxHeight");
        mMaxHeight.setAccessible(true);
        mMaxHeight.set(seekBar,Util.dip2px(this.getContext(),6));
       /* Field mMinHeight = superclass.getDeclaredField("mMinHeight");
        mMinHeight.setAccessible(true);
        mMinHeight.set(seekBar,Util.dip2px(this.getContext(),6));*/
    } catch (Exception e) {
        e.printStackTrace();
    }



    seekBar.setMinimumHeight(Util.dip2px(this.getContext(),6));

}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值