Issue
I tried this example. It's working fine. I want to implement a app that loads Google page directly.
I edited code. Here is my code:
public class MainActivity extends Activity {
private WebView browser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
browser = (WebView)findViewById(R.id.webView1);
browser.setWebViewClient(new MyBrowser());
}
public void open(View view) {
String myurl = "https://www.google.com";
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.loadUrl(myurl);
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
XML file:
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.sinlge.MainActivity" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Not giving any error but showing white page.
Solution
Please use
String myurl = "https://www.google.com";
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.loadUrl(myurl);
in onCreate
after
browser = (WebView)findViewById(R.id.webView1);
browser.setWebViewClient(new MyBrowser());
Because I am not able to see from where public void open(View view)
is being called.
Answered By - MysticMagicϡ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.