Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MainActivity.java file
- package asgor.net.myweb;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.view.Window;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- public class MainActivity extends Activity {
- private WebView mWebView;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().requestFeature(Window.FEATURE_NO_TITLE);
- mWebView = new WebView(this);
- mWebView.getSettings().setJavaScriptEnabled(true);
- mWebView.loadUrl("http://asgor.net/");
- mWebView.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- view.loadUrl(url);
- return true;
- }
- });
- this.setContentView(mWebView);
- }
- @Override
- public boolean onKeyDown(final int keyCode, final KeyEvent event) {
- if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
- mWebView.goBack();
- return true;
- }
- return super.onKeyDown(keyCode, event);
- }
- }
- //AndroidManifest.xml file
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="asgor.net.myweb" >
- <uses-permission android:name="android.permission.INTERNET"/>
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
- //add webViewClient for webView app.
- //Import this
- import android.webkit.WebViewClient;
- //then add this before load url.
- view.setWebViewClient(new WebViewClient());
- //Fixed orientation.
- android:screenOrientation="portrait"
- //Prevent reload page when orientation change.
- android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement