android - 如何在cardview和onclicklistener中设置预加载视频图片?

标签 android webview android-cardview android-youtube-api

我已经在 webview 中成功加载了视频,它也在播放,但我想将该链接传递给其他将使用 androidYouTubePlayer 播放视频的 Activity,并且我还想像下面那样显示该 webview。

问题:

  1. 如何像下面那样显示该视频
  2. 如何设置 OnclickListner 以将链接传递给其他 Activity 。

<android.support.v7.widget.CardView
                android:id="@+id/cardViewDemo1"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_margin="5dp"
                android:background="#00ff00"
                android:elevation="3dp"
                app:cardCornerRadius="5dp">

                <WebView
                    android:id="@+id/webView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="15dp" />
            </android.support.v7.widget.CardView>

最佳答案

将您的链接发送到新 Activity 。

CardView cardView = (CardView) findViewById(R.id.cardViewDemo1);

    cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String linkVideo = "Here, you set this string with link your video ";

            Bundle bundle = new Bundle();
            //HERE, YOU SET YOUR LINK VIDEO, INSIDE KEY "myKeyForReciveLinkVideo";
            bundle.putString("myKeyForReciveLinkVideo",linkVideo);

            //START YOUR ACTIVITY
            Intent i = new Intent(YourActivity,YourActivityGo.class);
           //Send your bundle containing the string with the url link to the new activity.
            startActivity(i,bundle);

        }
    });

在 Activity 中恢复传递给您的 Activity 的数据。

    //Retrieve the arguments passed to new activity.

    Bundle bundle = new Bundle(getArguments());

    //Use the key you previously defined in the bundle to retrieve the url link string.

    String urlLink = bundle.getString("myKeyForReciveLinkVideo");

希望对你有帮助

关于android - 如何在cardview和onclicklistener中设置预加载视频图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44862775/

相关文章:

java - 更改保存在 sd 卡中的目录

java - 用于字节码检索的解析器 dex 文件

android - 如何获取操作栏 View 对象?

android webview 页面在捕获图片并在 android 5+ 中上传后重新加载

java - 在 WebView 上加载 URL 之前无法加载图像

cocoa - 如何将 Webkit 插件添加到我的沙盒 OS X 应用程序 WebView 中?

Android - 隐藏软键盘慢

android - Cardview不可去除的灰色下划线(Android 4.0.4设备)

android - 坚持使用 Android 布局

Android 应用程序计费 - 在哪里放置绑定(bind)代码