繁体   English   中英

Webview应用程序不起作用

[英]Webview App doesn't work

我正在使用Webview开发一个应用程序。 我只是Android的初学者,所以我开始处理webViews。在模拟器中尝试使用webView时,它不会显示。 非常感谢您的帮助。 我目前正在使用eclipse juno 32位窗口。 我目前被困在这里。 这是

MainActivity.java

    package bulku.lucky;

    import android.support.v7.app.ActionBarActivity;
    import android.annotation.SuppressLint;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.webkit.WebView;

    @SuppressLint("SetJavaScriptEnabled") public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // applications are run through the emulator
        //to access "localhost" from the emulator



        String url = "http://e-promotion.al/";
        WebView view = (WebView) this.findViewById(R.id.webView1);
        view.getSettings().setJavaScriptEnabled(true);
        view.loadUrl(url);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    }

activity_main.xml中

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" />

AndroidManifest.xml中

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" tools:ignore="OldTargetApi"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

尝试将其添加到onCreate中(您必须添加一个新方法并在活动中调用他,onCreate方法必须尽可能干净,这只是一个提示。)

String url = "http://e-promotion.al/";
WebView view = (WebView) this.findViewById(R.id.webView1);  
view.getSettings().setJavaScriptEnabled(true);              
WebSettings settings = view.getSettings();
settings.getJavaScriptEnabled();
settings.getBuiltInZoomControls();
settings.setBuiltInZoomControls(true); // I use that to show a map in my app, you can delete this line if you want.
view.setWebViewClient(new WebViewClient());
view.loadUrl(url);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM