我已经在 webview 中成功加载了视频,它也在播放,但我想将该链接传递给其他将使用 androidYouTubePlayer 播放视频的 Activity,并且我还想像下面那样显示该 webview。
问题:
- 如何像下面那样显示该视频
- 如何设置 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/