Updated 18 December 2016
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?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"> <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="visible" android:layout_marginBottom="10dp" android:padding="10dp" /> </RelativeLayout> |
1 |
<uses-permission android:name="android.permission.INTERNET"/> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
WebView 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 webview webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); //use for RTL and LTR Languages if(getResources().getBoolean(R.bool.is_right_to_left)) { String text; text = "<html><body dir=\"rtl\"; style=\"text-align:justify;\">";//use for justify your text text += 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"); } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.