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