我正在开发一个应用程序,当用户从一个链接导航到另一个链接时,我想改变edittext
的内容,并想在edittext
中显示当前的网址。
但这三种方法都不起作用,甚至无法打印日志。以下是代码:
wv.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
String url_new = view.getUrl();
Log.v("","Webview URL: "+url);
addressbar.setText(url_new);
return false;
}
@Override
public void onPageFinished(WebView view, String url)
{
// TODO Auto-generated method stub
super.onPageFinished(view, url);
String url_new = view.getUrl();
Log.v("","Webview Function URL: "+url_new);
addressbar.setText(url_new);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
String url_new = view.getUrl();
Log.v("","Webview Function URL: "+url_new);
addressbar.setText(url_new);
}
});
wv
是上述代码中的WebView
,而addressbar
是EditText
。
我漏掉了什么?
请帮帮我..!!
编辑:全部代码..
public class Clip_From_Web_Home extends Activity
{
WebView wv;
TextView back, clip;
ProgressDialog dialog;
Button previous, reload, next, go;
LinearLayout ll;
public static final int REQUEST_CODE_CROP_IMAGE = 0x1;
Bitmap drawingCache;
public File mFileTemp;
public static final String TEMP_PHOTO_FILE_NAME = "temp_photo_web_clip.png";
FileOutputStream out;
EditText addressbar;
String url;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.clip_from_web);
wv = (WebView) findViewById(R.id.clip_from_web_webView1);
back = (TextView) findViewById(R.id.clip_from_web_textview_back);
back.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
finish();
}
});
url = "http://www.google.com";
addressbar = (EditText) findViewById(R.id.clip_web_address_bar);
addressbar.setText(url);
//wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
String url_new = view.getUrl();
Log.v("","Webview URL: "+url);
addressbar.setText(url_new);
return false;
}
@Override
public void onPageFinished(WebView view, String url)
{
// TODO Auto-generated method stub
super.onPageFinished(view, url);
String url_new = view.getUrl();
Log.v("","Webview Function URL: "+url_new);
addressbar.setText(url_new);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
String url_new = view.getUrl();
Log.v("","Webview Function URL: "+url_new);
addressbar.setText(url_new);
}
});
go = (Button) findViewById(R.id.clip_web_go);
go.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
url = addressbar.getText().toString();
Log.v("","URL ENTERED: "+url);
if(url.equals(""))
{
url = "http://www.google.com";
dialog = ProgressDialog.show(Clip_From_Web_Home.this,"","Loading",true,false);
new webview_load().execute();
}
else
{
dialog = ProgressDialog.show(Clip_From_Web_Home.this,"","Loading",true,false);
new webview_load().execute();
}
}
});
dialog = ProgressDialog.show(Clip_From_Web_Home.this,"","Loading",true,false);
new webview_load().execute();
}
class webview_load extends AsyncTask<Void, Void, Void>
{
@Override
protected Void doInBackground(Void... arg0)
{
// TODO Auto-generated method stub
return null;
}
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onPostExecute(Void result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
wv.setBackgroundColor(0);
wv.setBackgroundResource(android.R.color.black);
wv.setWebChromeClient(new WebChromeClient());
wv.setWebViewClient(new WebViewClient());
WebSettings settings = wv.getSettings();
settings.setBuiltInZoomControls(true);
//settings.setDefaultZoom(ZoomDensity.MEDIUM);
settings.setDefaultZoom(ZoomDensity.FAR);
wv.setInitialScale(125);
// settings.setUseWideViewPort(true);
settings.setRenderPriority(RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(false);
wv.loadUrl(url);
int secondsDelayed = 5;
new Handler().postDelayed(new Runnable()
{
public void run()
{
Log.v("","In Handler");
dialog.dismiss();
}
}, secondsDelayed * 1000);
}
}
}