android - CustomDialog Android 中的 VideoView

标签 android android-dialog android-videoview

我想使用 VideView 在自定义对话框中播放视频,但在对话框中我只得到标题,但既没有 VideoView 也没有按钮。请帮忙,有没有比自定义对话框??

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>

最佳答案

试一试它会起作用

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();

关于android - CustomDialog Android 中的 VideoView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35521216/

相关文章:

java - 无法从 firebase 数据库中检索值

Android App监控来电让手机保持清醒状态

android - 查看未附加到窗口管理器(解决方案是什么?)

android - ICS Holo Dialog 主题有什么问题?

java - 使用 oncreateoptionsmenu 中的 Android youtube 播放器 Activity

java - VideoView onTouch 事件 : pause/resume video, 和显示/隐藏 MediaController 和 ActionBar

java - 我怎样才能使这段代码更有效率?

java - 获取 .apk 文件的主包名称

android - HTTP 请求中的 WebView cookie

kotlin - 如何处理对话框中的取消和确定按钮