【发布时间】:2013-04-16 03:04:57
【问题描述】:
我有一个这样的 xml 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:background="#262626">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EXIT" />
<ScrollView
android:id="@+id/sv2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp" android:background="#ffffff">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/add_webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:scrollbarStyle="insideOverlay"
android:text="@string/desc" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
我想在我的应用程序中加载我的 Url,并保留我在 webView 上方创建的按钮。 不幸的是,我在设备浏览器的新窗口中获得了 webView。
这就是我调用 webView 的方式:
WebView add_webView = (WebView) dialog
.findViewById(R.id.add_webView);
add_webView.loadUrl(MYLINK);
我怎样才能让我的 webView 进入我的应用程序而不是浏览器窗口? 谢谢!!:)
【问题讨论】:
-
您的应用是否在清单文件中声明了 INTERNET 权限?
-
是的。页面加载成功,但不是在我的应用程序中,而是在浏览器窗口中(在我的应用程序之外)
-
在我看来你肯定正确地使用了 loadURL。developer.android.com/reference/android/webkit/…
-
那是我的问题...根据文档,我的方式是正确的...但是我的 webView 在浏览器窗口中而不是在我的应用程序中启动...而且我一直在使用一个非常简单的网站作为 www.google.com 来测试它
-
您是否有理由在对话框中调用 findViewById 而不是活动本身?调试时是否在尝试加载 URL 之前分配了 WebView?