gpt4 book ai didi

java - 无法在 webview 中加载 url - 黑屏

转载 作者:行者123 更新时间:2023-12-02 10:24:13 26 4
gpt4 key购买 nike

我一直在尝试几种方法,其中一些在这里找到,在我的应用程序中使用 webview 加载 url,但到目前为止,对于来自客户端的一个特定页面,所有这些方法都没有成功。让我们以这种方法为例:

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/background">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@drawable/top_heading"
android:id="@+id/rlayout1">
<TextView android:layout_width="wrap_content"
android:layout_centerVertical="true" android:layout_centerHorizontal="true"
android:textColor="#ffffff" android:textSize="22dip"
android:textStyle="bold" android:layout_height="wrap_content"
android:text="More Information" android:id="@+id/txtviewfbdisplaytitle" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_below="@+id/rlayout1"
android:id="@+id/rlayout2">
<WebView android:id="@+id/webview1" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0" />
</RelativeLayout>
</RelativeLayout>

MainActivity.Java

public class MainActivity extends Activity {
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Button btnBack;
WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

webview=(WebView)findViewById(R.id.webview1);
webview.setWebViewClient(new MyWebViewClient());
openURL();
}

/** Opens the URL in a browser */
private void openURL() {
webview.loadUrl("[see solution]");
webview.requestFocus();
}
}

虽然其他网站可以工作,但这个网站却不行。我对 Android 编程相当陌生。接下来我可以尝试什么?

附带问题:URL 有什么不同的作用来阻止成功加载?

最佳答案

该网站使用 DOM 存储来运行,并且由于默认情况下 DOM 存储在 android webview 中处于禁用状态,因此您必须启用它。

webview.setWebViewClient(new MyWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
openURL();

关于java - 无法在 webview 中加载 url - 黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54097683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com