我想使用VideView在自定义对话框中播放一个视频,但是在对话框中,我只得到标题,而不是VideoView或button.Please帮助,还有比自定义对话框更好的方式在活动上显示视频吗?
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.introvid);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
final VideoView viz = (VideoView) dialog.findViewById(R.id.vid123);
Uri vidUri = Uri.parse(feedob);
vid.setVideoURI(vidUri);
vid.start();
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();自定义对话框的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:id="@+id/vid123"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="Back "
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="@+id/vid123"
/>
</RelativeLayout>发布于 2016-02-20 09:16:23
试试这个,它会起作用的
final Dialog dialog = new Dialog(yourclassname.this);// add here your class name
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.yourxml);//add your own xml with defied with and height of videoview
dialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.copyFrom(dialog.getWindow().getAttributes());
dialog.getWindow().setAttributes(lp);
uriPath= "android.resource://" + getPackageName() + "/" + R.raw.yourvid;
getWindow().setFormat(PixelFormat.TRANSLUCENT);
Log.v("Vidoe-URI", uriPath+ "");
mVideoView.setVideoURI(Uri.parse(uriPath));
mVideoView.start();https://stackoverflow.com/questions/35521216
复制相似问题