3

在 WebView 中启用或禁用的设置是什么?

4

3 回答 3

6

如果您想使用与原生 android 浏览器具有完全相同功能的 webview,则必须检查许多选项和设置。WebView 不使用所有浏览器选项和设置,以获得更好的性能,并更好地控制用户在浏览时可以做什么和不可以做什么。找出你应该在这里阅读 api 文档的所有机会:http: //developer.android.com/reference/android/webkit/WebView.html

For some further dealing and handling with the WebView class also here are some usefull sample codelines: http://pankajchunchun.wordpress.com/2013/01/09/example-of-webview-with-result-handler-and-connection-timeout-handler/

I hope this will help you.

于 2013-09-26T08:35:49.090 回答
2

这是 webview 示例源..

你想知道什么样的设置??

public class MainActivity extends Activity {
    WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webview = (WebView)findViewById(R.id.webview);
        webview.setWebViewClient(new WebClient()); 
        WebSettings set = webview.getSettings();
        set.setJavaScriptEnabled(true);
        set.setBuiltInZoomControls(true);
        webview.loadUrl("http://www.google.com");

        findViewById(R.id.btnStart).setOnClickListener(onclick);
    }

    OnClickListener onclick =new OnClickListener() {

        @Override
        public void onClick(View v) {
            String url= null;
            EditText add = (EditText)findViewById(R.id.add);
            url = add.getText().toString();
            webview.loadUrl(url);           
        }
    };

    class WebClient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
于 2013-09-26T08:27:56.280 回答
0

In addition to @Ssam's answer, you might want to manage the back button press so your app/Activity doesn't get closed on back press.

@Override
    public void onBackPressed() {
        if (webview.canGoBack()) {
            webview.goBack();
        }else
            super.onBackPressed();

    }

where webview is your webview

于 2020-01-30T06:10:55.970 回答