Tuesday, 20 October 2015

How to make WebView app in android studio

1:Open an Android Studio 2:Click on Start a new android Project then Click Next
3:Change Application name and Company Domain then Click Next
4:Select Phone and Tablet and choose android 2.2(Froyo)
5:Select Blank Activity then Click Next
6:After completing step 5,this windows will open
7:Delete Hello World (Right-click on hello world and delete it)

MainActivity.java

package com.ingenicotribe.m.androidwebview; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.KeyEvent; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends AppCompatActivity { private WebView myWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myWebView = (WebView) findViewById(R.id.webView); WebSettings webSettings = myWebView.getSettings(); myWebView.setWebViewClient(new WebViewClient()); webSettings.setJavaScriptEnabled(true); myWebView.loadUrl("http://yourdomain.com"); } @Override public void onBackPressed() { if (myWebView.canGoBack()) { myWebView.goBack(); } else { super.onBackPressed(); } } }

content_main.xml




&lt; <relativelayout android:layout_height="match_parent" android:layout_width="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".MainActivity" 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"> <webview android:id="@+id/webView" android:layout_height="match_parent" android:layout_width="match_parent"> </webview></relativelayout>

activity_main.xml




<android .support.design.widget.coordinatorlayout="" android:fitssystemwindows="true" android:layout_height="match_parent" android:layout_width="match_parent" tools:context=".MainActivity" 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"> <include layout="@layout/content_main"> </include></android>

AndroidManifest.xml




<manifest package="your pakage name" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/Theme.AppCompat.NoActionBar"> <activity android:label="@string/app_name" android:name=".MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN"> <category android:name="android.intent.category.LAUNCHER"> </category></action></intent-filter> </activity> </application> <uses-permission android:name="android.permission.INTERNET"> </uses-permission></manifest>

Styles.xml




<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="android:windowNoTitle">true</item> </style> <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> </resources>

Share

& Comment

6 comments:

  1. this is really nice to read..informative post is very good to read..thanks a lot! iPhone Repair Dubai

    ReplyDelete
  2. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! website

    ReplyDelete
  3. This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… hoverwatch cost

    ReplyDelete
  4. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page! android

    ReplyDelete
  5. Very informative post ! There is a lot of information here that can help any business get started with a successful social networking campaign ! Asus ZenWatch

    ReplyDelete

 

Copyright © Taha Codes™ is a registered trademark.