我有一个应用程序从网页中获取一些文本,并将其显示在屏幕上。我想在网页后面放一段视频。我怎么能这样做?如果我喜欢下面的代码,应用程序崩溃(空指针异常)。Android视频嵌入
我的代码:
LinearLayout tt= (LinearLayout)findViewById(R.id.kiu);
WebView webview;
tt.addView(fin); // fin is the TextView
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.youtube.com/embed/j4Wmjl7jxQo");
tt.addView(webview);
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="#FFFFFF"
>
<LinearLayout
android:id="@+id/kiu"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="0dp">
</LinearLayout>
</ScrollView>
我想不出该怎么办。我想我的应用程序,以显示this而不是this。
如果我在xml中创建webview,当我输入包含文本的活动时,我会自动定向到youtube。我希望在那里嵌入视频,当我点击它时,将被重定向到页面。你能告诉我我该怎么做? – Teo
然后您需要第一个选项。摆脱xml中的webview,并摆脱findViewById()调用,并使用webview = new WebView(this);并把tt.addView(webview);在你调用loadUrl()之后 – FoamyGuy