0

我认为一段语法可以浏览本地网页。但我想隐藏地址。我测试了很多次都不成功。

package org.webViewEx;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewEx extends Activity {

    // Controls
    private WebView m_webView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Initialize controls
        m_webView = (WebView)findViewById(R.id.wvBrowser);

        // Initialize web view
        WebSettings webViewSettings = m_webView.getSettings();
        webViewSettings.setJavaScriptEnabled(true);
        webViewSettings.setDomStorageEnabled(true);
        webViewSettings.setDatabaseEnabled(true);
        webViewSettings.setDatabasePath("/data/data/"+getPackageName()+"/databases");

        // Override functions so that javascript alert() and confirm() can work
        m_webView.setWebChromeClient(new WebChromeClient()
        {
            @Override
            public boolean onJsAlert(WebView view, String url, String message,
                    final JsResult result)
            {
                new AlertDialog.Builder(WebViewEx.this)
                .setMessage(message)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        result.confirm();
                    }})
                .show();

                return true;
            }

            @Override
            public boolean onJsConfirm(WebView view, String url,
                    String message, final JsResult result)
            {
                new AlertDialog.Builder(WebViewEx.this)
                .setMessage(message)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        result.confirm();
                    }})
                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        result.cancel();
                    }})
                .show();

                return true;
            }
        });

        // Initialize a webview client


        m_webView.setWebViewClient(new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl("file:///android_asset/ts.htm");
                return true;
            }
        });

        // Show main page
        m_webView.loadUrl("file:///android_asset/anttree.htm");
    }
}

我从网上了解到。使用这种方法可以成功隐藏。

m_webView.setWebViewClient(new WebViewClient()

{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl("file:///android_asset/ts.htm");
        return true;
    }
});

但是没用 告诉我怎么做 thx

4

1 回答 1

4

中没有地址栏WebView。问题已经在这里说明:禁用地址栏Android webview

您可能想要的是删除标题。如果我没记错的话,活动标题中也会注明名称/网址。你应该阅读:http: //developer.android.com/resources/tutorials/views/hello-webview.html

您可以通过在您的manifest file.

<activity android:name=".MyActivity" android:label="@string/app_name"
 android:theme="@android:style/Theme.NoTitleBar">
于 2013-01-12T08:40:31.507 回答