2015-04-03 154 views
1

如何以编程方式更改MediaController图标?我的意思是播放/暂停/转发和rew以编程方式更改MediaController图标

enter image description here

你看,我已经加入全屏按钮,但不能认识到如何改变这三个。

定制的MediaController类:

public class CustomVideoController extends MediaController { 
public static boolean full = false; 

private ImageButton fullScreenBtn; 
Context mContext; 
Activity activity; 
VideoView mVideoView; 

public CustomVideoController(Context context, Activity activity, VideoView videoView) { 
    super(new ContextThemeWrapper(context, R.style.VideoPlayerTheme)); 
    this.activity = activity; 
    mContext = context; 
    mVideoView = videoView; 
} 

@Override 
public void setAnchorView(View view) { 
    super.setAnchorView(view); 
    FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(
      LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
    frameParams.gravity = Gravity.RIGHT | Gravity.TOP; 
    frameParams.setMargins(12,14,10,12); 

    View v = AddFullScreenBtn(); 
    addView(v, frameParams); 
} 

@Override 
public void hide() { 
    super.hide(); 
} 

@Override 
public void show(int timeout) { 
    super.show(0); 
} 

private View AddFullScreenBtn() { 
    fullScreenBtn = new ImageButton(mContext); 
    if (full) 
     fullScreenBtn.setImageResource(R.drawable.ic_media_fullscreen_stretch); 
    else 
     fullScreenBtn.setImageResource(R.drawable.ic_media_fullscreen_shrink); 
    fullScreenBtn.setBackgroundColor(Color.WHITE); 
    fullScreenBtn.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      if (full){ 
       fullScreenBtn.setImageResource(R.drawable.ic_media_fullscreen_stretch); 
       activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
       full = false; 
      } else { 
       fullScreenBtn.setImageResource(R.drawable.ic_media_fullscreen_shrink); 
       activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
       full = true; 
      } 
     } 
    }); 
    return fullScreenBtn; 
} 

请帮我更改这些图标绘项目。它有可能吗?我真的很困惑那个。

回答

1

如果我理解正确,那么您使用的是android.widget.MediaControleller。在这种情况下,无法更改布局按钮。这里的原因(代码波纹管是从MediaController.class):

/** 
    * Create the view that holds the widgets that control playback. 
    * Derived classes can override this to create their own. 
    * @return The controller view. 
    * @hide This doesn't work as advertised 
    */ 
    protected View makeControllerView() { 
     LayoutInflater inflate = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     mRoot = inflate.inflate(com.android.internal.R.layout.media_controller, null); 

     initControllerView(mRoot); 

     return mRoot; 
    } 

正如你所看到的,它使用私有方法sutup和夸大其观点。

+0

但是有没有一种方法来欺骗或应用自定义布局? – AnZ 2015-04-03 10:43:42

+1

@AnZ我不这么认为。这是一个随时可用的小部件,因此无法像这样修改它,但是您可以看看它是如何完成的并实现完全自己的MediaController – 2015-04-03 11:03:14

+0

,并且如果我在SDK中替换图标? – AnZ 2015-04-04 12:34:32

相关问题