info@thistimebd.com

Thursday 21st of November 04:03:54pm

android web apps source code

MainActivity.java

----------------

package com.thistimebd.web.webapp;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.webkit.WebSettings;

import android.webkit.WebView;

import android.webkit.WebViewClient;


public class MainActivity extends AppCompatActivity {


    private WebView webView;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        webView=(WebView) findViewById(R.id.webViewId);

        WebSettings webSettings=webView.getSettings();

        webSettings.setJavaScriptEnabled(true);

        webView.setWebViewClient(new WebViewClient());

        webView.loadUrl("http://www.ox.ac.uk");

    }


    @Override

    public void onBackPressed() {

      if (webView.canGoBack()){

          webView.goBack();



      }else{


          super.onBackPressed();

      }

    }

}

----------------------------------------------------

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>

======================================================================

activity_main.xml

-------------------

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context="com.thistimebd.web.webapp.MainActivity">


<WebView

    android:id="@+id/webViewId"

    android:layout_width="match_parent"

    android:layout_height="match_parent">



</WebView>


</LinearLayout>

==================================================================

AndroidManifest.xml

-----------------

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.thistimebd.web.webapp">

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


    <application

        android:allowBackup="true"

        android:icon="@drawable/uk"

        android:label="@string/app_name"

        android:roundIcon="@drawable/uk"

        android:supportsRtl="true"

        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>


</manifest>