2

I want to display the webview,admob and a navbar which contains an edit text and 2 buttons in the same page.But the page automatically goes to the webview (as in the browser) hiding the other elements defined in the activity....The code is given below...please give your valuable suggestions...Thank you in advance...

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <include android:id="@+id/nav_bar_layout" layout="@layout/nav_bar" android:layout_above="@+id/web_view" /> <WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/web_view" android:layout_centerInParent="true" /> <include android:id="@+id/admob_layout" layout="@layout/admob_layout" android:layout_below="@+id/web_view" /> </RelativeLayout> 
2

2 Answers 2

8

You can use setWebViewClient(). Setting your own custom WebViewClient lets you handle onPageFinished, shouldOverrideUrlLoading.

webview=(WebView)findViewById(R.id.webView1); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("file:///android_asset/index.htm"); webview.setWebViewClient(new WebViewClient()); 
Sign up to request clarification or add additional context in comments.

2 Comments

But Another problem followed the Web page doesn't load...It shows a blank screen....
see the edited code: you can add any web page and load it in webview using loadUrl method. here i have added index.htm page under assets folder
0

Use ScrollView. As content of webview will be more so it will occupy whole screen if you have given as android:layout_height="wrap_content"

Or Else given fix height to webview

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/bg_2"> <RelativeLayout android:id="@+id/mainLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/txtTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="Title" /> <WebView android:id="@+id/txtDescription" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtTitle" android:layout_margin="10dp"/> <TextView android:id="@+id/txtDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtDescription" /> </RelativeLayout> </ScrollView> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.