Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show the web page within your application using webview in android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 304
    Comment on it

    If you want to show web pages without opening browser application in your android application then make the use of webview as I have done below:-

    1) to make your application access the internet use the permission"<uses-permission android:name="android.permission.INTERNET"/>" in your manifest file.

    2) Use the <webview> tag in your xml file where you want to show the web page.

    activity_main.xml

    <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="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
    
        <Button
            android:id="@+id/btn"
            android:text="Click"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:visibility="gone"
            />
    
    </RelativeLayout>
    

     

    3) Now initialize the webview in your java file as shown below

    MainActivity.java

    public class MainActivity extends AppCompatActivity {
        private WebView mweView;
        private Button btn;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            btn=(Button)findViewById(R.id.btn);
            btn.setOnClickListener(mClickListener);
    
        }
    
        View.OnClickListener mClickListener=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    
                webview();
            }
        };
    
        private void webview()
        {
            mweView=(WebView)findViewById(R.id.webview);
            
            btn.setVisibility(View.GONE);
            mweView.setVisibility(View.VISIBLE);
    
    //will open all hyperlinks on your web page within your app
            mweView.setWebViewClient(new WebViewClient());
    
    // shows the particular url in your app
            mweView.loadUrl("http://www.evontech.com/");
    
    
        }
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: