如何将网页制作成Android应用

马特·密码人

嗨,我正在尝试制作一个基于Web的应用程序,但是我是一个初学者,不能100%地确定我现在正在做什么,请您指导我没有错误,但是它说应用程序在运行时没有响应


主Java


    package com.theverge.www.theverge;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    import static com.theverge.www.theverge.R.id.*;


    public class TheVerge extends Activity {

        private WebView the_verge;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_the_verge);

             the_verge = (WebView) findViewById(activity_the_verge_webview);
            // Enable Javascript
            WebSettings webSettings = the_verge.getSettings();
            webSettings.setJavaScriptEnabled(true);
            // Force links and redirects to open in the WebView instead of in a browser
            the_verge.setWebViewClient(new WebViewClient());
            the_verge.loadUrl("http://www.theverge.com");
        }


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_the_verge, 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();

            //noinspection SimplifiableIfStatement
            if (id == action_settings) {
                return true;
            }

            return super.onOptionsItemSelected(item);
        }
    }

这是主要活动的xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
    android:id="@+id/activity_the_verge_webview"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".TheVerge">

    <TextView android:text="" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


AndroidManfest xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.theverge.www.theverge" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".TheVerge"
            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>
比丹

您需要将WebView添加到布局文件中。将其更改为这样的内容

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
android:id="@+id/activity_the_verge_webview"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".TheVerge">

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

然后onCreate()用这个替换你的方法

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_the_verge);

         the_verge = (WebView) findViewById(webView1);
        // Enable Javascript
        WebSettings webSettings = the_verge.getSettings();
        webSettings.setJavaScriptEnabled(true);
        // Force links and redirects to open in the WebView instead of in a browser
        the_verge.setWebViewClient(new WebViewClient());
        the_verge.loadUrl("http://www.theverge.com");
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将数据从网页传递到要在iOS和Android上安装的应用程序

来自分类Dev

如何将 SRT 文件制作成数据集?

来自分类Dev

如何将android分区的图像制作到您的PC

来自分类Dev

如何将Google Identity Toolkit与单个网页应用程序(例如GWT)集成

来自分类Dev

如何将数据从应用程序直接发布到网页?

来自分类Dev

如何将网页下载为.mhtml

来自分类Dev

如何将网页的正文对齐中心?

来自分类Dev

如何将网页分成“部分”

来自分类Dev

如何将 Lex 与网页集成

来自分类Dev

将网页的元素绑定到Android应用

来自分类Dev

WPF:如何将Mahapps Metro应用程序重新制作为类库?

来自分类Dev

如何将纹理应用于使用挤压制作的对象

来自分类Dev

如何将图像的不同区域制作成按钮(swift/xcode)?

来自分类Dev

如何将 FunctionTransformer 与 GridSearchCV 一起制作成管道?

来自分类Dev

如何将广播限制为自己的Android应用

来自分类Dev

如何将Facebook分享添加到Android应用

来自分类Dev

如何将Codeigniter API连接到Android应用

来自分类Dev

如何将Android版的应用邀请与Facebook集成?

来自分类Dev

如何将 GPS 设备与 Android 应用程序连接

来自分类Dev

如何快速制作我的Android应用

来自分类Dev

如何快速制作我的Android应用

来自分类Dev

如何制作可扩展的网页

来自分类Dev

如何制作简单的网页导航?

来自分类Dev

如何从网页制作屏幕截图?

来自分类Dev

如何将网页另存为PDF?

来自分类Dev

如何将网页加载到<div>元素中?

来自分类Dev

如何将Firefox网页另存为图像

来自分类Dev

如何将参数传递到SPARQL网页查询中

来自分类Dev

如何将错误消息从SQL Server返回到网页

Related 相关文章

热门标签

归档