如何将响应式网站转换为Android应用程序

时间:2016-02-02 11:39:41

标签: android wordpress android-layout responsive-design

我最近开发了一个使用WordPress的网站。它有一个完全响应的模板。我想为该网站制作一个Android应用程序。是否有可用于开发应用程序的快捷方式?我的意思是我可以将网站转换为移动应用程序吗?

我知道我的问题与编码无关,但我真的需要一些帮助。!

5 个答案:

答案 0 :(得分:1)

创建MyAppWebViewClient.java文件

package com.example.test;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MyAppWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(Uri.parse(url).getHost().endsWith("websitename.com")) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}

在MainActivity.java中编写代码

package com.example.test;

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


public class MainActivity extends Activity {
    WebView mwebview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mwebview=(WebView) findViewById(R.id.webVieww);
        WebSettings websetting=mwebview.getSettings();
        websetting.setJavaScriptEnabled(true);
        mwebview.loadUrl("http://websitename.com");
        //mwebview.setWebViewClient(new WebViewClient());
        mwebview.setWebViewClient(new MyAppWebViewClient());
    }

    @Override
    public void onBackPressed() {
        if(mwebview.canGoBack()) {
            mwebview.goBack();
        } else {
            super.onBackPressed();
        }
    }
    @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_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();

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

        return super.onOptionsItemSelected(item);
    }
}

放入activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    tools:ignore="MergeRootFrame">

    <WebView
        android:id="@+id/webVieww"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

答案 1 :(得分:0)

&#34;更容易&#34;您可以使用的方法是在Android中创建一个只有WebView here的新应用程序,您可以轻松找到它的工作原理,在此链接中您有official documentation

PS:这是一种简单的方法,如果您的网站具有响应能力,并且可以轻松地适应看起来像应用程序的手机网站,请使用这种方式,但不建议开发一个网站应用程序&#34; 。如果你有移动网站,你的应用应该有更多的东西。像菜单,一些登录功能,这样的东西。

如果可能的话,我建议你开发一个完整的应用程序。您可以使用所有网站的图片和图案,但它会有所不同。

祝你好运!

答案 2 :(得分:0)

如果仍然有用,我最近发现有一项服务可以将任何响应式网站转换/打包为android apk:applika.me

答案 3 :(得分:-1)

您可以使用插件Apppresser执行此操作。这个插件从wordpress网站创建应用程序。基本插件是免费的,您可以轻松使用它。

答案 4 :(得分:-1)

从WordPress网站创建应用程序的WordPress插件:
1.普通的WebView应用程序
2. PhoneGap Webview应用程序
3. AppPresser
4.沃罗纳
5. Project App插件
6.本机应用程序
7. Bobile
8. WordPress REST API

相关问题