1

I would like to imitate the behavior of the default android browser - The EditText (the address bar) on top will start to "disappear" once the user scrolls down. The only thing I can think of right now is to put the EditText and the WebView in a ScrollView but that would create other problems, and is not recommended.

What do you think?

Alex1987
  • 9,397
  • 14
  • 70
  • 92

2 Answers2

0

Create a custom View by extending WebView and override onScrollChanged(). With a little calculations you can accomplish your task.

Alex Orlov
  • 18,077
  • 7
  • 55
  • 44
  • So basically what you are saying is that I will have to "push" the address bar out of the bounds of the screen? Isn't there any "elegant" way to do it? – Alex1987 Feb 10 '11 at 14:31
  • That's what I was implying. Changing the editbox's position depending on the current scroll. Not any, that i'm aware of. – Alex Orlov Feb 10 '11 at 14:39
0

What problems does your ScrollView cause? This one should work fine:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0" android:orientation="vertical">

 <ScrollView android:layout_width="fill_parent" android:layout_gravity="top" android:layout_height="fill_parent">
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0" android:orientation="vertical">
 <EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:text="yourtexthere" android:layout_gravity="bottom" android:layout_height="wrap_content">
 </EditText> 
     <WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/myWebView"></WebView>
 </LinearLayout>
 </ScrollView>

</LinearLayout>
NoBugs
  • 9,310
  • 13
  • 80
  • 146
  • 1
    In my opinion this standalone solution provides bad user experience due to ugly scrolling of the WebView. See my answer here in order to provide better user experience while placing webview inside a scroll view - [TolerantScrollView](http://stackoverflow.com/a/12963499/1152250) – rus1f1kat0R Oct 19 '12 at 16:04