Android webview browser edit text automatically change with webview change -
i make webview in android . there webview , edit text , go button . want when webview change edit text automatically change current url . example: when type url "www.google.com" go google if go youtube google edit text stands "www.google.com". want edit text automaticlly change current webview java code
package com.example.ashraful.userinterface; import android.app.activity; import android.graphics.bitmap; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.keyevent; import android.view.view; import android.view.window; import android.webkit.websettings; import android.webkit.webview; import android.widget.button; import android.widget.edittext; import android.widget.progressbar; public class main2activity extends activity { webview web1; edittext ed1; button bt1; string address; string add; progressbar pbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.activity_main2); web1 =(webview)findviewbyid(r.id.webview1); ed1 = (edittext)findviewbyid(r.id.edittext1); bt1 = (button)findviewbyid(r.id.button1); pbar = (progressbar)findviewbyid(r.id.progressbar1); pbar.setvisibility(view.gone); bt1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { address = "http://" + ed1.gettext().tostring(); websettings websetting = web1.getsettings(); websetting.setbuiltinzoomcontrols(true); websetting.setjavascriptenabled(true); websetting.setloadsimagesautomatically(true); web1.setwebviewclient(new webviewclient()); web1.loadurl(address); } }); } public class webviewclient extends android.webkit.webviewclient { @override public void onpagestarted(webview view, string url, bitmap favicon) { // todo auto-generated method stub super.onpagestarted(view, url, favicon); pbar.setvisibility(view.visible); } @override public boolean shouldoverrideurlloading(webview view, string url) { // todo auto-generated method stub view.loadurl(url); return true; } @override public void onpagefinished(webview view, string url) { // todo auto-generated method stub super.onpagefinished(view, url); pbar.setvisibility(view.gone); } } @override public boolean onkeydown(int keycode, keyevent event) { if ((keycode == keyevent.keycode_back) && web1.cangoback()) { web1.goback(); return true; } return super.onkeydown(keycode, event); } }
the xml code
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main2" 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.ashraful.userinterface.main2activity"> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_alignparenttop="true" android:text="go" /> <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbottom="@+id/button1" android:layout_alignparentleft="true" android:ems="10" android:hint="type url here" android:layout_toleftof="@+id/button1" android:layout_tostartof="@+id/button1" /> <view android:id="@+id/view12" android:layout_width="wrap_content" android:layout_height="3dp" android:layout_alignbottom="@+id/button1" android:layout_alignparentleft="true" android:background="#3bbdfa" /> <webview android:id="@+id/webview1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/edittext1" android:layout_centerhorizontal="true" /> <progressbar android:id="@+id/progressbar1" style="?android:attr/progressbarstylelarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </relativelayout>
try set edittext in onpagefinished or/and in onpagestarted method:
ed1.settext(""); // clear ed1.settext(view.geturl()); // set current url
Comments
Post a Comment