Sreekanth Karumanaghat
Sreekanth Karumanaghat

Reputation: 3403

Webview loads url in browser window instead of Webview

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>

Upvotes: 2

Views: 2794

Answers (2)

Ponmalar
Ponmalar

Reputation: 7031

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());

Upvotes: 8

Nirali
Nirali

Reputation: 13825

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>

Upvotes: 0

Related Questions