我正在创建一个Android应用程序,其中我必须显示Twitter的Hash Tag链接但是当我在我们的自定义webview中加载它时它将在默认浏览器中打开。可以帮助我如何在Web视图中打开它那么在默认的浏览器中?
链接是: https://mobile.twitter.com/search/%23nokia
...谢谢
WebViewClient yourWebClient = new WebViewClient()
{
/* Override page so it's load on my view only */
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// This line we let me load only pages inside Firstdroid Webpage
if ( url.contains("firstdroid") == true )
/* Load new URL Don't override URL Link */
return false;
// Return true to override url loading (In this case do nothing).
return true;
}
};
// Get Web view
mWebView = (WebView) findViewById( R.id.WebView ); //This is the id you gave
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(true); //Zoom Control on web (You don't need this
//if ROM supports Multi-Touch
mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
mWebView.setWebViewClient(yourWebClient);
// Load URL
Log.v("", ""+web2);
mWebView.loadUrl(web2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v("", "EXECUTED");
//website.this.finish();
Intent ii = new Intent(getParent(), Socialsites.class);
TabGroupActivity parentActivity3 = (TabGroupActivity)getParent();
// ii.putExtra("WEB", six.get(arg2));
parentActivity3.startChildActivity("bb", ii);
}
});
答案 0 :(得分:1)
起诉你有权访问互联网
在Manifest中。
<uses-permission android:name="android.permission.INTERNET" />
xml布局
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
并加载您的网址
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("https://mobile.twitter.com/search/%23nokia");
答案 1 :(得分:1)
将shouldOverrideUrlLoading()内的load.loadUrl(url)写入:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
答案 2 :(得分:0)
你怎么用:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl("https://mobile.twitter.com/searches");
needReload = true;
return true;
}
然后你将函数onPageFinished重载为:
@Override
public void onPageFinished(WebView view, String url) {
setProgressBarIndeterminateVisibility(false);
progess.setVisibility(View.GONE);
if(needReload){
view.loadUrl("javascript:location.search = \"q=%23nokia\"");
needReload = false;
}
}
它将重新加载页面,搜索诺基亚术语 您可以通过以下方式替换诺基亚:
view.loadUrl("javascript:location.search = \"q=%23" +searchTerms +"\"");
获得更灵活的东西。