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>
Ponmalar
  • 6,871
  • 10
  • 50
  • 80
Sreekanth Karumanaghat
  • 3,383
  • 6
  • 44
  • 72

2 Answers2

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());
Ponmalar
  • 6,871
  • 10
  • 50
  • 80
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>
Nirali
  • 13,571
  • 6
  • 40
  • 53