【问题标题】:Webview App doesn't workWebview 应用程序不起作用
【发布时间】:2014-07-21 16:12:15
【问题描述】:

我正在开发一个使用 web 视图的应用程序。我只是 Android 的初学者,我开始处理 webViews 当我在我的模拟器中尝试它时它没有出现。非常感谢您的帮助。我目前正在使用 eclipse juno 32 位 windows 。我目前被困在这里。这是

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>

【问题讨论】:

    标签: java android xml eclipse webview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-30
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多