目前我正在运行标签式布局......但是在标签中我希望有网页浏览...
我得到的问题是,由于某些原因,因为选项卡shouldOverrideUrlLoading不起作用,它仍然会打开浏览器......
这是我的来源:
我的主要活动:
package app.numbers4sports.com;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
public class numbers4sports extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, CounterActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("counter").setIndicator("COUNTER",
res.getDrawable(R.drawable.ic_tab_counter))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, HelpActivity.class);
spec = tabHost.newTabSpec("help").setIndicator("HELP",
res.getDrawable(R.drawable.ic_tab_help))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, HomeActivity.class);
spec = tabHost.newTabSpec("home").setIndicator("ORDER",
res.getDrawable(R.drawable.ic_tab_home))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
我的家庭活动(第一次网络浏览):
package app.numbers4sports.com;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class HomeActivity extends Activity {
WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.numbers4sports.com");
}
private class abcd extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
答案 0 :(得分:1)
我的代码中没有看到WebView.setWebViewClient()?
答案 1 :(得分:0)
mWebView。 setWebViewClient() {
@覆盖
//在WebView中显示而不是在浏览器中显示 public boolean shouldOverrideUrlLoading(WebView view,String url)
{
view.loadUrl(URL);
返回true;
}
}
答案 2 :(得分:-1)
确保正确放置WebViewClient
并确保您写下return true;
。