使用Android studio做一个简单的网站APP

1、首先创建一个空白Android项目

2、然后打开项目,切换为Android视图,这时候会看到三个文件夹,分别是manifests、java、res。首先修改res/layout下的activity_web.xml布局文件,内容为:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

3、修改java文件夹项目下的MainActibity.java文件。该文件就是程序的入口,也是默认的程序首页,内容为一个TextView控件。

package com.irunker.visant;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

@SuppressLint("SetJavaScriptEnabled")
public class main extends AppCompatActivity {
    private WebView myWebView = null;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        // 打开网页
        myWebView = (WebView) findViewById(R.id.webview);
        myWebView.loadUrl("http://www.irunker.com/");
        //设置可自由缩放网页、JS生效
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);  
        webSettings.setBuiltInZoomControls(true);
        // 修改默认在WebView中打开链接
         myWebView.setWebViewClient(new WebViewClient());
    }

    // 按键响应,在WebView中查看网页时,按返回键的时候按浏览历史退回,如果不做此项处理则整个WebView返回退出
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack())
        {
            // 返回键退回
            myWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

4、修改程序的主配置文件AndroidManifest.xml。 该文件声明程序中的Activities, ContentProviders, Services, 和Intent Receivers,permissions和instrumentation等。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.irunker.visant">
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".main">
            <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

5、最后修改一下res/value文件夹下的styles.xml样式.保证无多余的顶部样式,只是显示一个网页。

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

然后选中项目右键单击,选择new–Image assert,会弹出出一个窗口,勾选Image在image file中进行选择电脑中的图标,设置完成之后,完成即可。

6、这样一个简单的网站APP就制作完成了。

源码:https://github.com/shaonanwei/irunker

  • 6
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值