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

    Related Post

    发表评论

    邮箱地址不会被公开。 必填项已用*标注