自定义 Android VideoView 界面的外观
如何自定义 Android 中 VideoView 界面的外观?我特别想用我自己的按钮替换进度条、黄色背景和媒体(暂停/播放)按钮。
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/surface_view"
android:layout_width="320px"
android:layout_height="240px"/>
</LinearLayout>
代码
public class VideoViewExample extends Activity {
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.sm));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
}
}
How can I customize the look and feel of VideoView interface in Android? I'd especially like to replace the progress bar, yellow background and media(pause/play) buttons with my own.
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/surface_view"
android:layout_width="320px"
android:layout_height="240px"/>
</LinearLayout>
Code
public class VideoViewExample extends Activity {
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.sm));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那不是“VideoView 用户界面”。这就是
MediaController
。也许可以设置MediaController
的样式,尽管我上次选择替换它遇到这个问题。That is not "the
VideoView
user interface". That is theMediaController
. It may be possible to style theMediaController
, though I just elected to replace it the last time I encountered this issue.