Wrapping HTML in an app for Android

前端 未结 2 1657
无人及你
无人及你 2021-02-08 22:21

I have an existing site (social in nature) and it already has a mobile web version too, so what I basically want to do is wrap that view in an Android app and maybe add a nice s

相关标签:
2条回答
  • 2021-02-08 23:14

    You would need two activites

    • Splash Screen (use a timer and after x seconds move to the next activity)
    • Main

    In the main activity you would need to set a layout with a webView in your layout so something like:

    <?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"
    />
    

    and the code:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.google.com");
    }
    

    and the permissions:

    <uses-permission android:name="android.permission.INTERNET" />
    

    in the manifest file.

    If you want to turn the title bar off you will also need to add:

    <activity android:name=".Main" android:label="@string/app_name"
     android:theme="@android:style/Theme.NoTitleBar">
    

    Read the docs for more help! An example for Google for this exactly and I referenced is http://developer.android.com/resources/tutorials/views/hello-webview.html

    0 讨论(0)
  • 2021-02-08 23:15

    There also exist several frameworks that wrap HTML5 inside a native app and gives you access to APIs.

    Phonegap is the most well-known http://phonegap.com/

    0 讨论(0)
提交回复
热议问题