There are some situations may occur where you want to add an embed video in your android applications with some text in android. So the simplest way, you choose the WebView.
Steps.
- Create a layout for WebView-
1234567891011121314<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/white"><WebViewandroid:id="@+id/webView"android:layout_width="match_parent"android:layout_height="wrap_content"android:visibility="visible"android:layout_marginBottom="10dp"android:padding="10dp"/></RelativeLayout> - Add Internet permission code on your manifest.xml –
1<uses-permission android:name="android.permission.INTERNET"/>
- Add the following code on your Activity –
12345678910111213141516171819202122232425262728WebView webView = ((WebView) v.findViewById(R.id.webView));String embedString ="<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/videoseries?list=PLrjT1qW1v6ykZlUHxFkha1AXR9xlZW2ga\" frameborder=\"0\" allowfullscreen></iframe>"String descriptionText = "your text"String descriptionText = " your Text";// use for embeded youtube link in webviewwebView.setWebViewClient(new WebViewClient() {@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {return false;}});WebSettings webSettings = webView.getSettings();webSettings.setJavaScriptEnabled(true);webView.getSettings().setLoadWithOverviewMode(true);//use for RTL and LTR Languagesif(getResources().getBoolean(R.bool.is_right_to_left)) {String text;text = "<html><body dir=\"rtl\"; style=\"text-align:justify;\">";//use for justify your texttext += descriptionText + embedString ;text += "</body></html>";webView.loadData(text, "text/html; charset=UTF-8", "utf-8");}else{String text;text = "<html><body style=\"text-align:justify;\">";text += descriptionText + embedString;text += "</body></html>";webView.loadData(text, "text/html", "utf-8");}