简体   繁体   English

页面正在浏览器而不是Webview上打开

[英]page is opening on browser instead of Webview

I tried to create an app where it should open my webapp on localhost. 我尝试创建一个应在本地主机上打开我的webapp的应用程序。 I used webapp, but instead of showing up as an app, it asked me to choose internet browser. 我使用了webapp,但没有显示为应用程序,而是要求我选择Internet浏览器。 What should I do? 我该怎么办? Here's the code. 这是代码。

activity_main.xml activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".WebView" >

    <WebView
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"

         />


</RelativeLayout>

MainActivity.java MainActivity.java

package com.example.suryaagung;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.webkit.WebView;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends ActionBarActivity {

    @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //No title bar is set for the activity
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //Full screen is set for the Window
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);
        final WebView SuryaAgung = (WebView)findViewById(R.id.main);
        SuryaAgung.loadUrl("http://localhost:8080/app");
        SuryaAgung.getSettings().setJavaScriptEnabled(true);
      }
    }

AndroidManifest.xml AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.suryaagung"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

This should work: 这应该工作:

final WebView SuryaAgung = (WebView)findViewById(R.id.main);
SuryaAgung.setWebViewClient(new WebViewClient());
SuryaAgung.getSettings().setJavaScriptEnabled(true);
SuryaAgung.loadUrl("http://localhost:8080/app");

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

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