Webview应用程序不起作用

时间:2014-07-21 16:12:15

标签: java android xml eclipse webview

我正在开发一个使用webview的应用程序。我只是Android的初学者,我开始处理webViews当我在我的模拟器中尝试它时,它没有显示出来。真的很感谢你的帮助。我目前正在使用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>

1 个答案:

答案 0 :(得分:0)

尝试将此添加到您的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);