com.elkriefy.android.apps.chubbytabby.activity.WebViewActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.elkriefy.android.apps.chubbytabby.activity.WebViewActivity.java

Source

package com.elkriefy.android.apps.chubbytabby.activity;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.elkriefy.android.apps.chubbytabby.R;

public class WebViewActivity extends AppCompatActivity {

    public static final String EXTRA_URL = "com.elkriefy.android.apps.chubbytabby.activity.WebViewActivity.EXTRA_URL";
    WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        mWebView = (WebView) findViewById(R.id.web_view);
        String url = getIntent().getStringExtra(EXTRA_URL);
        mWebView.setWebViewClient(new WebViewClient());
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl(url);
        setupActionBar(url);
    }

    private void setupActionBar(String url) {
        setTitle(url);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null)
            actionBar.setDisplayHomeAsUpEnabled(true);
    }
}