Android App Code For Browser

Click Hire Me For Making Android App to go to Create Android App
Here three type of file mainactivity.xml, mainactivity.java and manifest.xml all file are using in android studio application.



how to create a web Browser android app like chrome, firebox, fbrowser, etc. first you have to download Android Studio after create a new project and then put the code in your xml, java manifest file respectively.



CODE IS BELOW


MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="687dp"0
    android:background="dccdc"
    android:soundEffectsEnabled="true"


    tools:context=".MainActivity">

    <Button
        android:id="@+id/button1"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/Untitled"

        android:layout_alignParentEnd="true" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentLeft="true"

        android:ems="10"
        android:hint="Type Your URL Here"
        android:layout_alignParentStart="true" />

    <View
        android:id="@+id/view12"
        android:layout_width="wrap_content"
        android:layout_height="3dp"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentLeft="true"
        android:background="#3bbdfa"
        android:layout_alignParentStart="true" />

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

</RelativeLayout>




MainActivity.java

package com.tseriez.fbrowser;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;


public class MainActivity extends Activity {

    WebView web1;
    EditText ed1;
    Button bt1;
    String Address;
    String add;
    ProgressBar pbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        web1 = (WebView)findViewById(R.id.webView1);
        ed1 = (EditText)findViewById(R.id.editText1);
        bt1 = (Button)findViewById(R.id.button1);
        pbar = (ProgressBar)findViewById(R.id.progressBar1);
        pbar.setVisibility(View.GONE);

        bt1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Address = "http://" + ed1.getText().toString();
                WebSettings webSetting = web1.getSettings();
                webSetting.setBuiltInZoomControls(true);
                webSetting.setJavaScriptEnabled(true);

                web1.setWebViewClient(new WebViewClient());

                web1.loadUrl(Address);

            }
        });
    }

    public class WebViewClient extends android.webkit.WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {

            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
            pbar.setVisibility(View.VISIBLE);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            // TODO Auto-generated method stub
            view.loadUrl(url);
            return true;
        }
        @Override
        public void onPageFinished(WebView view, String url) {

            // TODO Auto-generated method stub

            super.onPageFinished(view, url);
            pbar.setVisibility(View.GONE);
        }

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && web1.canGoBack()) {
            web1.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}




Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fbrowser">


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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        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>

Comments

Popular posts from this blog

Identify Security Threats