Search code examples
androidwebviewandroid-internet

How load specific web pages on my android application?


Please don't minus my question if it is wrong i am new on android. I want in my application have a connection to about us of my site. means when press a button open about us of my site and show information of that. How should implement it?


Solution

  • you should have an activity that embed a webview. In the onclick of your button, you have to launch it.

    button = (Button) findViewById(R.id.buttonUrl);
    
            button.setOnClickListener(new OnClickListener() {
    
              @Override
              public void onClick(View arg0) {
                Intent intent = new Intent(context, WebViewActivity.class);
                startActivity(intent);
              }
    

    In the webview class

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);
    
            webView = (WebView) findViewById(R.id.webView1);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("http://www.google.com");
    
        }
    

    Normally it will do what you want.