Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tutorial Java Code :
- package com.example.gypsy;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.webkit.WebChromeClient;
- import android.webkit.WebView;
- public class Tutorials extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_tutorials);
- WebView webView1 = findViewById(R.id.webView1);
- loadYouTubeVideo(webView1, "https://www.youtube.com/embed/fEPalyEJ9gk?si=A71htOWYpm0mk0g9");
- WebView webView2 = findViewById(R.id.webView2);
- loadYouTubeVideo(webView2, "https://www.youtube.com/embed/V2KCAfHjySQ?si=NVvmLaslMPR7Io7o");
- WebView webView3 = findViewById(R.id.webView3);
- loadYouTubeVideo(webView3, "https://www.youtube.com/embed/L482ZAno-fY?si=MoeQoVu7YVmxK_Ha");
- WebView webView4 = findViewById(R.id.webView4);
- loadYouTubeVideo(webView4, "https://www.youtube.com/embed/_ttcR7VDouE?si=As-s6H47gW7oPssU");
- WebView webView5 = findViewById(R.id.webView5);
- loadYouTubeVideo(webView5, "https://www.youtube.com/embed/hb_iMGC3Wyo?si=aVfXZTMPeN4k_iKj");
- }
- private void loadYouTubeVideo(WebView webView, String videoUrl) {
- String iframe = "<iframe width=\"100%\" height=\"100%\" src=\"" +
- videoUrl +
- "\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen></iframe>";
- webView.loadData(iframe, "text/html", "utf-8");
- webView.getSettings().setJavaScriptEnabled(true);
- webView.setWebChromeClient(new WebChromeClient());
- }
- }
- XML Code :
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:fillViewport="true">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="How To Train Your Dragon" />
- <WebView
- android:layout_width="match_parent"
- android:layout_height="250sp"
- android:id="@+id/webView1" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="How To Train Your Dragon" />
- <WebView
- android:layout_width="match_parent"
- android:layout_height="250sp"
- android:id="@+id/webView2" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="How To Train Your Dragon" />
- <WebView
- android:layout_width="match_parent"
- android:layout_height="250sp"
- android:id="@+id/webView3" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="How To Train Your Dragon" />
- <WebView
- android:id="@+id/webView4"
- android:layout_width="match_parent"
- android:layout_height="250sp" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="How To Train Your Dragon" />
- <WebView
- android:id="@+id/webView5"
- android:layout_width="match_parent"
- android:layout_height="250sp" />
- </LinearLayout>
- </ScrollView>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement